Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created February 2, 2020 14:56
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 magdamiu/8154994950a816cd9e3bd6a55189036f to your computer and use it in GitHub Desktop.
Save magdamiu/8154994950a816cd9e3bd6a55189036f to your computer and use it in GitHub Desktop.
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