Skip to content

Instantly share code, notes, and snippets.

@tikidunpon
Created September 26, 2016 11:13
Show Gist options
  • Save tikidunpon/020a9dd84ae79da511ac64eccd677512 to your computer and use it in GitHub Desktop.
Save tikidunpon/020a9dd84ae79da511ac64eccd677512 to your computer and use it in GitHub Desktop.
data class便利だよねー #kotlin_power, #CodePiece #kotlin
data class User(val name: String, val id: Int)
fun getUser(): User {
return User("Alex", 1)
}
fun main(args: Array<String>) {
val user = getUser()
println("name = ${user.name}, id = ${user.id}")
// or
val (name, id) = getUser()
println("name = $name, id = $id")
// or
println("name = ${getUser().component1()}, id = ${getUser().component2()}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment