🐦 Kotlin
Intermediate
What is the @JvmStatic annotation in Kotlin?
Answer
By default, companion object methods are instance methods of the companion singleton, not static methods in the JVM bytecode. This means Java code must call them as MyClass.Companion.method(). Annotating a companion object method with @JvmStatic generates an additional static method in the enclosing class's bytecode, allowing Java callers to use the natural MyClass.method() syntax. Similarly, @JvmField exposes a companion property as a real static field. These annotations are important for maintaining clean Java interoperability in mixed Kotlin-Java codebases or when publishing Kotlin libraries for Java consumption.