Guest User

Untitled

a guest
Jan 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. data class Person(val name: String) {
  2. var age: Int = 0
  3. }
  4.  
  5. fun main(args: Array<String>) {
  6. println(Person("Adam")) // Person(name=Adam)
  7.  
  8. // Note: This also means that `age` will be excluded from the auto generated equals and hashCode methods.
  9. // So even though these people have different ages, they are treated as equal.
  10. // You may find a use case for this, but it is important to be aware of.
  11. val adam1 = Person("Adam")
  12. adam1.age = 20
  13. val adam2 = Person("Adam")
  14. adam2.age = 50
  15. println(adam1 == adam2) // true
  16. println(adam1.hashCode() == adam2.hashCode()) // true
  17. }
Add Comment
Please, Sign In to add comment