With the code below, I am getting the following error in IntelliJ IDEA 13.1.6 and Kotlin plugin 0.11.91.AndroidStudio.3:

Platform declaration clash: The following declarations have the same JVM signature (getName()Ljava/lang/String;):
  • public open fun getName(): kotlin.String?
  • internal final fun <get-name>(): kotlin.String?

Java类,JavaInterface.java:

public interface JavaInterface {
  public String getName();
}

Kotlin 班,KotlinClass.kt

public class KotlinClass(val name: String?) : JavaInterface

我已经try 通过

我可以通过这样做找到一个解决方法:

public class KotlinClass(val namePrivate: String?) : JavaInterface {
  override fun getName(): String? = namePrivate
}

But in my real-world case I have a number of properties to implement and need setters too. Doing this for each property doesn't seem very Kotlin-ish. What am I missing?

推荐答案

把变量设为private就解决了这个问题.

public class KotlinClass(private val name: String?) : JavaInterface

Kotlin相关问答推荐

如何在Kotlin中模拟www.example.com()?

Spring Boot kotlin协程不能并行运行

如何创建一个空的kotlin工作?

在 Kotlin 中将两个字节转换为 UIn16

在 map 中查找键与在 kotlin 中查找 firstOrNull

kotlin 父类具有依赖于抽象变量的变量

将 SharedPreferences 中的值公开为流

Kotlin 编译器在构造函数中报告未使用的表达式,以便构建器采用 vararg lambda

如何在 jOOQ 中两次加入同一张表?

KMM:编译失败:意外的 IrType 类型:KIND_NOT_SET

关于 Kotlin 函数类型转换的问题

在 kotlin 中写入 parcer 可空值

kotlin,如何从函数返回类类型

在 Scaffold Jetpack Compose 内的特定屏幕上隐藏顶部和底部导航器

为什么 Dialog 没有 NavController [Missing]?

是否在Kotlin中重写enum toString()?

Android 上的 Kotlin:将map到list

kotlin 委托有什么用?

将 Double 转换为 ByteArray 或 Array Kotlin

如何修复未解析的参考生命周期范围?