Kotlin: 'public' property exposes its 'local' type argument <no name provided>

Viewed 280
interface A {
    fun f() : String
}

val B = { attr : String ->
    object : A {
        override fun f() = attr
    }
}

I'm getting this error at the definition of B:

'public' property exposes its 'local' type argument <no name provided>

What is the cause of this error?

1 Answers

You are returning an anonymous singleton object, and kotlin is not able to figure out the type for which no name is provided. You can specify the type of B explicitly to fix this issue

val B: (String) -> A = { attr: String ->
    object : A {
        override fun f() = attr
    }
}
Related