You can use Kotlin bytecode viewer to find out what these options are compiled to.
With Kotlin 1.0.2 the compiled bytecode shows that
-
valproperty inobjectorcompanion objectis compiled into aprivate static finalfield inside the class:// access flags 0x1A private final static I FILES_TO_DOWNLOAD = 100and a getter, which is called when referring to the property:
// access flags 0x1019 public final static synthetic access$getFILES_TO_DOWNLOAD$cp()IFrom Java, the getter can be called as
DefaultValues.INSTANCE.getFILES_TO_DOWNLOAD()orDefaultValues.Companion.getFILES_TO_DOWNLOAD()respectively. -
Non-
consttop level property is compiled to the same to (1) with only difference that the field and getter are placed insideFilenameKtclass now.But top level
const valis compiled into apublic static finalfield:// access flags 0x19 public final static I DEFAULT_FILES_TO_DOWNLOAD = 100The same public static final field will be produced when a
const valis declared inside an object. Also, you can achieve the same resulting bytecode if you add@JvmFieldannotation to the properties declared in (1).
Concluding that, you can define public static final field using const or @JvmField either in an object or at top level.