import java.util.* class Animal { var age = 0 get() = field set(value) { if(value >= 0) { field = value } else { throw Error("bad number") } } } fun main() { val animal = Animal() animal.age = 8 println(animal.age) // 8 animal.age = -2 // Error: bad number }