Last active
February 19, 2019 11:42
-
-
Save renaudcerrato/7a2ff057697157a91cae4d53e043b725 to your computer and use it in GitHub Desktop.
Kotlin Delegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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