https://kotlinlang.org logo
r

Ruckus

05/21/2018, 6:20 PM
So, I have an interesting problem. This does not work, because
value
is not initialized. What is the correct way to do this?
Copy code
class Validated(val validator: Validator, default: Any) {
    var value: Any
        set(value) {
            if (!validator.valid(value)) error("invalid")
            field = value
        }

    init {
        value = default
    }
}