package loaderman.democlass Person { val name: String get() = "name" var v: Int = 0 var value: Int get() = v set(value) { println("设值" + value) v = value }}
package loadermanimport loaderman.demo.Personfun main(arg: Array) { var p = Person() println( p.v) p.value=80 println( p.v)}
filed标识符,可以将filed 当作成员变量使用,也就是通过field读写属性值
package loaderman.democlass Person { val name: String get() = "name" var value: Int=0 get() =field set(value) { println("设值" + value) field = value }}
package loadermanimport loaderman.demo.Personfun main(arg: Array) { var p = Person() p.value=80 println( p.value)}