Created
April 11, 2019 13:53
-
-
Save vodamiro/05e6d466ac05e60d77c520d518c1ef70 to your computer and use it in GitHub Desktop.
S_A_DataClasses.kt
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
// Example of data class (saved more than 10 lines in comparison to Java) | |
data class User(val name: String, val surname: String, val age: Int) | |
// Example of custom getters and setters on a property | |
class MrUser { | |
var name: String = "" | |
get() { | |
return "Mr. $field" // Get name with "Mr." prefix | |
} | |
set(newValue) { | |
println("old: '$field', new: '$newValue'") // Print change | |
field = newValue // Store new value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment