According Kotlin documentation this is equivalent:
class Hello {
companion object {
const val MAX_LEN = 20
}
}
Usage:
fun main(srgs: Array<String>) {
println(Hello.MAX_LEN)
}
Also this is static final property (field with getter):
class Hello {
companion object {
@JvmStatic val MAX_LEN = 20
}
}
And finally this is static final field:
class Hello {
companion object {
@JvmField val MAX_LEN = 20
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…