Slide 24
Slide 24 text
Calling Kotlin from Java - Static Methods
Kotlin can generate static methods for functions defined in named objects or
companion objects if you annotate those functions as @JvmStatic
class C {
companion object {
@JvmStatic fun foo() {}
fun bar() {}
}
}
Now, foo() is static in Java, while bar() is not:
C.foo(); // works fine
C.bar(); // error: not a static method
C.Companion.foo(); // instance method remains
C.Companion.bar(); // the only way it works