How do I initialize a final field in Kotlin?
You can set val
value in init block:
class MyClass {
val s: String
init {
s = "value"
}
}
You can also initialize the value with by lazy
the value will be initialized the first time it is referred. An example
val s by lazy { RemoteService.result() }
kotlin will guess the type of s from the return type of the expression.