Skip to content

Instantly share code, notes, and snippets.

@aaronoe
Last active January 6, 2019 19:33
Show Gist options
  • Select an option

  • Save aaronoe/7c384d04d6eb2be3208acebafe10f52f to your computer and use it in GitHub Desktop.

Select an option

Save aaronoe/7c384d04d6eb2be3208acebafe10f52f to your computer and use it in GitHub Desktop.
val myProperty by CounterProperty("foo")
class CounterProperty(private val value: String) : ReadOnlyProperty<Any, String> {
private var counter = 0
override fun getValue(thisRef: Any, property: KProperty<*>): String {
return synchronized(counter) {
println("Counter: ${++counter}")
value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment