August 2018
Beginner
178 pages
4h 56m
English
Kotlin doesn't have the static keyword, but to achieve compatibility with Java, it provides support for it with annotations. Kotlin provides the @JvmStatic and @JvmField annotations, which, when applied to a member of a class, make it static.
In this example, the @JvmStatic annotation will tell the compiler to compile the annotated function to a static one, and the @JvmField will tell the compiler to compile the annotated property to a static field, without getters and setters:
class Static { companion object { // static method @JvmStatic fun staticFunction() { } // static field @JvmField val staticField = 0 }}
Read now
Unlock full access