Search code examples
javakotlincompanion-objectkotlin-companion

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.


Solution

  • you just need to add JvmStatic annotation

    companion object{
        @JvmStatic
        val x=10
    }