Last active
January 13, 2022 07:08
-
-
Save PragmaticCoding/34b03c5530a07313dca2f4c27b4c5785 to your computer and use it in GitHub Desktop.
Kotlin Property with Overriden Getter and Setter
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 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