Skip to content

Instantly share code, notes, and snippets.

@Temidtech
Created April 23, 2018 13:35
Show Gist options
  • Save Temidtech/003da0bcd46e616ea575b20ef393d2cd to your computer and use it in GitHub Desktop.
Save Temidtech/003da0bcd46e616ea575b20ef393d2cd to your computer and use it in GitHub Desktop.
//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