Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created Feb 2, 2020
Embed
What would you like to do?
Data class in Kotlin
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