@JvmField exposes a Kotlin property as a public Java field, making it useful when Java code requires field-based access rather than Kotlin-generated accessors. section 4.4.3 section 12.1.2
Expose an object property as a Java field
object BuildConfig { @JvmField val version = "1.0" } /* Java */ String version = BuildConfig.version; section 4.4.3 section 12.1.2
Apply the annotation to a top-level property or a property declared in an object when the Java-facing API must contain a field. Unlike @JvmStatic, which exposes methods as static Java methods, @JvmField changes property visibility for Java callers. section 4.4.3 section 12.1.2
Use @JvmField when these conditions apply:
- Java integration requires direct field access. section 4.4.3
- The declaration is a top-level property or belongs to an object. section 4.4.3
- The Java API should provide no getter or setter for the property. section 12.1.2
