更新时间:2023-11-17 14:20:10
实际上Kotlin知道示例中这两种方法之间的区别,但jvm不会.这就是为什么它是平台"冲突的原因.
Actually Kotlin knows the difference between the two methods in your example, but jvm will not. That's why it's a "platform" ***.
您可以使用@JvmName
批注来编译第二个示例:
You can make your second example compile by using the @JvmName
annotation:
class Foo {
@JvmName("barString") fun bar(foo: List<String>): String {
return ""
}
@JvmName("barInt") fun bar(foo: List<Int>): String {
return "2";
}
}
这个注释之所以存在是因为这个原因.您可以在 interop中阅读更多内容.文档.
This annotation exists for this very reason. You can read more in the interop documentation.