Skip to content

Commit

Permalink
Kotlin observable 观察者
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterZhang committed Jun 28, 2017
1 parent 19871a0 commit ec6f15a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/com/betterzhang/learnkotlin/kotlin/Observable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.betterzhang.learnkotlin.kotlin

import kotlin.properties.Delegates

/**
* Created by IntelliJ IDEA.
* Author : Andrew Zhang
* Email : betterzhang.dev@gmail.com
* Time : 2017/06/28 下午 2:12
* Desc : Kotlin observable 观察者
*/
class Person2 {
public var name: String by Delegates.observable("init...") {
property, oldValue, newValue -> println("property: $property, oldValue: $oldValue, newValue: $newValue")
}
}
fun main(args: Array<String>) {
val person = Person2()
println(person.name)

person.name = "Andrew Zhang"
person.name = "Kotlin"
}

0 comments on commit ec6f15a

Please sign in to comment.