Created
February 2, 2020 14:56
-
-
Save magdamiu/8154994950a816cd9e3bd6a55189036f to your computer and use it in GitHub Desktop.
Data class in Kotlin
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
data class Character(val name: String, val age: Int) | |
fun main() { | |
val mickeyMouse = Character("Mickey Mouse", 82) | |
val mickeyMouseToday = mickeyMouse.copy(age = 83) | |
// destructuring declarations | |
val (name, age) = mickeyMouseToday | |
println("$name, $age years of age") | |
mickeyMouseToday.component1() // => name | |
mickeyMouseToday.component2() // => age | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment