set get 的使用
This commit is contained in:
parent
00bf7c5676
commit
62fb58b0fe
17
src/main/kotlin/Demo1/SetGet.kt
Normal file
17
src/main/kotlin/Demo1/SetGet.kt
Normal 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
|
||||
*/
|
Loading…
Reference in New Issue
Block a user