Java 科特林:';公共';属性公开其';本地';类型参数<;未提供名称>;
我在Java 科特林:';公共';属性公开其';本地';类型参数<;未提供名称>;,java,kotlin,lambda,Java,Kotlin,Lambda,我在B的定义中得到了这个错误: interface A { fun f() : String } val B = { attr : String -> object : A { override fun f() = attr } } “public”属性公开其“local”类型参数 此错误的原因是什么?您正在返回一个匿名单例对象,而kotlin无法找出未提供名称的类型。您可以明确指定B的类型来解决此问题 'public' property ex
B
的定义中得到了这个错误:
interface A {
fun f() : String
}
val B = { attr : String ->
object : A {
override fun f() = attr
}
}
“public”属性公开其“local”类型参数
此错误的原因是什么?您正在返回一个匿名单例对象,而kotlin无法找出未提供名称的类型。您可以明确指定
B
的类型来解决此问题
'public' property exposes its 'local' type argument <no name provided>
val B: (String) -> A = { attr: String ->
object : A {
override fun f() = attr
}
}