class MyAwesomeActivity {
companion object {
val KEY = "MyAwesomeKey"
}
}
==
public final class MyAwesomeActivity {
@NotNull
private static final String KEY = "MyAwesomeKey";
public static final MyAwesomeActivity.Companion Companion = new MyAwesomeActivity.Companion((DefaultConstructorMarker)null);
public static final class Companion {
@NotNull
public final String getKEY() {
return MyAwesomeActivity.KEY;
}
private Companion() {
}
// $FF: synthetic method
public Companion(DefaultConstructorMarker $constructor_marker) {
this();
}
}
}
// MyAwesomeActivity.kt file
const val STATIC_FIELD = "MyAwesomeKey1"
class MyAwesomeActivity{
companion object{
const val INNER_STATIC_FIELD = "MyAwesomeKey2"
}
}
==
public final class MyAwesomeActivityKt {
@NotNull
public static final String STATIC_FIELD = "MyAwesomeKey";
}
public final class MyAwesomeActivity {
@NotNull
public static final String INNER_STATIC_FIELD = "MyAwesomeKey2";
public static final MyAwesomeActivity.Companion Companion = new MyAwesomeActivity.Companion((DefaultConstructorMarker)null);
public static final class Companion {
private Companion() {
}
// $FF: synthetic method
public Companion(DefaultConstructorMarker $constructor_marker) {
this();
}
}
}
In conclusion, if you just need a static field I would suggest to declare the field asconst val
outside the class to avoid having a companion object and the relatedinner static class,
alternatively just remember to useconst
inside the companion object to at least avoid the getter method.