Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active February 19, 2019 11:42
Show Gist options
  • Save renaudcerrato/7a2ff057697157a91cae4d53e043b725 to your computer and use it in GitHub Desktop.
Save renaudcerrato/7a2ff057697157a91cae4d53e043b725 to your computer and use it in GitHub Desktop.
Kotlin Delegate
class Capitalizer {
var value: String? = null
operator fun getValue(thisRef: Any?, property: KProperty<*>): String? {
return value
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String?) {
this.value = value?.capitalize()
}
}
class Person {
var firstName by Capitalizer()
var lastName by Capitalizer()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment