Let's say we have an object such as
object MyConstants {
const val ONE: String = "One"
}
The generated bytecode resembles
public final class MyConstants {
@NotNull
public static final String ONE = "One";
public static final MyConstants INSTANCE;
private MyConstants() {}
static {
MyConstants var0 = new MyConstants();
INSTANCE = var0;
}
}
Is there a way to avoid generating the INSTANCE field while maintaining the same code layout? That means accessing fields through class both in Kotlin and Java
MyConstants.ONE
object. It implies creating an object that you can use just like any other object. An object without instance is a contradiction. You can use top-level constants if you don't want an object. TheMyConstants.CONSTANTsmells like Java to me, as this "pattern" was an effect of the language forcing you to put everything inside classesconst val ONE = "Oneas its only content?