Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 805
thewolf Avatar asked Oct 18 '25 15:10

thewolf


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
    }
}
like image 167
sidgate Avatar answered Oct 21 '25 04:10

sidgate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!