Skip to content

Instantly share code, notes, and snippets.

@PragmaticCoding
Last active January 13, 2022 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PragmaticCoding/34b03c5530a07313dca2f4c27b4c5785 to your computer and use it in GitHub Desktop.
Save PragmaticCoding/34b03c5530a07313dca2f4c27b4c5785 to your computer and use it in GitHub Desktop.
Kotlin Property with Overriden Getter and Setter
class KotlinClass() {
public var nickName: String = ""
set(value) {
field = value
println("in the setter")
}
get() {
println("in the getter")
return field
}
}
fun main(args: Array<String>) {
val testClass = KotlinClass()
testClass.nickName = "Shorty"
println("Nickname: ${testClass.nickName}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment