EsbenG
EsbenG

Reputation: 28162

Why do we get a weird method name when calling kotlin object from java?

In kotlin I have a class that was converted to an object and now when I call it from java the method name is appended with $app. What does this mean?

Kotlin

object SomeObject {
    internal val standardRetroService: WebPredictionService
        get() = getCustomBaseRetroService(CloudUtil.doStuff)
}

Java

SomeObject.INSTANCE.getStandardRetroService$app().dostuff();

Upvotes: 2

Views: 228

Answers (1)

zsmb13
zsmb13

Reputation: 89668

You get that postfix because of the internal visibility modifer, which makes the property visible only within its module (app) when using it from Kotlin.

There isn't such a visibility in Java / on the bytecode level, so instead the identifier gets "mangled" with this this postfix, which is supposed to signal to Java clients that they shouldn't be using it, at least if they aren't sure they know what they're doing.

Upvotes: 3

Related Questions