Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 科特林:';公共';属性公开其';本地';类型参数<;未提供名称>;_Java_Kotlin_Lambda - Fatal编程技术网

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
    }
}