set get 的使用

This commit is contained in:
Yutousama 2022-05-11 17:36:48 +08:00
parent 00bf7c5676
commit 62fb58b0fe
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package Demo1
class SetGet {
var index:Int=0
get() { return field+10}
set(value) {
field = (value * 10)
}
}
fun main(args: Array<String>) {
val tmp=SetGet()
tmp.index=10
println(tmp.index)
}
/** out **
* 110
*/