Skip to content

Commit

Permalink
Kotlin Getter and Setter
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 29, 2017
1 parent 3536106 commit 54493e2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/KotlinGetterAndSetter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.betterzhang.learnkotlin.kotlin

import java.util.*

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/29 下午 5:20
* Desc : Kotlin Getter and Setter
*/
class KotlinGetterAndSetter {

var x: Int = 0
set(value) {field = value}
get() = field

var y: Int = 0
set(value) {
var date = Calendar.getInstance().apply {
set(2017, 2, 18)
}
if (System.currentTimeMillis() < date.timeInMillis) {
println("Cannot be set before 2017.3.18")
} else {
field = value
}
}
get() {
println("Get field y: $field")
return field
}

}

0 comments on commit 54493e2

Please sign in to comment.