class Age() {
var age: Int = 4
val isYoung get() = age < 30
// var isYoung get() = age < 30 // Property must be initialized
Hello, I have a question about Kotlin’s Getter
.
When using get()
in the property of class, val
has no problem, but var
has a Property must be initialized
error.
As far as I know, the difference between val and var is whether the value can be changed or not.
So I don’t understand exactly why this error occurs.