如何在Kotlin中创建常量?什么是命名惯例?我没有在文档中找到它.
companion object {
//1
val MY_CONST = "something"
//2
const val MY_CONST = "something"
//3
val myConst = "something"
}
Run Code Online (Sandbox Code Playgroud)
要么 ...?
我有一个关于Enum的问题.
我有一个enum类,如下所示
public enum FontStyle {
NORMAL("This font has normal style."),
BOLD("This font has bold style."),
ITALIC("This font has italic style."),
UNDERLINE("This font has underline style.");
private String description;
FontStyle(String description) {
this.description = description;
}
public String getDescription() {
return this.description;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道这个Enum对象何时被创建.
枚举看起来像'静态最终'对象,因为它的值永远不会改变.因此,在此目的中,仅在编译时初始化是有效的.
但它在顶层调用自己的构造函数,所以我怀疑它可以在我们调用它时生成,例如,在switch语句中.