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

Warpzit :

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();
zsmb13 :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=147508&siteId=1