Skip to content

Instantly share code, notes, and snippets.

@Temidtech
Created June 28, 2019 13:46
Show Gist options
  • Save Temidtech/1bf9e8d7c7dfe248cb024da882e203c1 to your computer and use it in GitHub Desktop.
Save Temidtech/1bf9e8d7c7dfe248cb024da882e203c1 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