Skip to content
Advertisement

Why Companion object is not accessible from Java code?

As we know Kotlin and Java are inter-operable. When I try to access Java static variable inside Kotlin code it works, but when I try to access companion object in Java, it does not work.

Advertisement

Answer

you just need to add JvmStatic annotation

companion object{
    @JvmStatic
    val x=10
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement