Created
June 28, 2019 13:46
-
-
Save Temidtech/1bf9e8d7c7dfe248cb024da882e203c1 to your computer and use it in GitHub Desktop.
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
//Declare a Person Class | |
data class Person(val name: String) { | |
var age: Int = 0 | |
} | |
val person1 = Person("John") | |
val person2 = Person("John") | |
person1.age = 10 | |
person2.age = 20 | |
// copy an object | |
fun copy(name: String = this.name, age: Int = this.age) = User(name, age) | |
val jack = User(name = "Jack", age = 1) | |
val olderJack = jack.copy(age = 2) | |
// prints "Jane, 35 years of age" | |
val jane = User("Jane", 35) | |
val (name, age) = jane | |
println("$name, $age years of age") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment