【发布时间】:2019-09-24 02:50:57
【问题描述】:
我目前正在使用 kotlin 开发一个多平台模块。为此,我依靠expect/actual mechanism。
我在Common.kt中声明了一个简单的类:
expect class Bar constructor(
name: String
)
我想在一个通用方法中使用定义的类(也存在于Common.kt):
fun hello(bar: Bar) {
print("Hello, my name is ${bar.name}")
}
实际实现定义在Jvm.kt:
actual data class Bar actual constructor(
val name: String
)
问题是我的hello 函数中出现以下错误
未解析的引用:名称
我做错了什么?
【问题讨论】:
-
尝试从期望类中删除
constructor。
标签: kotlin kotlin-multiplatform kmm