- Type: Design proposal
- Author: Mike Bogdanov
- Status: Implemented in Kotlin 1.3
- Discussion: KEEP-152
Allow to use @JvmField
annotation on interface companion properties similar to class companion ones.
@JvmField
annotation on interface companion properties has same effect and similar restrictions as annotation on class companion members:
- generates static field in interface with initialization in interface
- adding or removing
@JvmField
annotation is binary incompatible change cause it's changes fields owner - not applicable for
const
,lateinit
and delegated properties - property should not have any custom accessors
- property can't override anything
- applicable only if all companion properties are
public final val
annotated with@JvmField
(additional restriction)
interface Foo {
companion object {
@JvmField
val foo: String = "bar"
}
}
Maybe weak additional condition ("all companion properties are public final val
annotated with @JvmField
")
to allow use const
properties withing @JvmField
ones.
In such case const
properties should also be moved to interface
(NB: now additional declaration copy is created in interface for const
property in companion)
- KT-15807 @JvmField is not applicable to interface companion properties