Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data class Person(val name: String) {
- var age: Int = 0
- }
- fun main(args: Array<String>) {
- println(Person("Adam")) // Person(name=Adam)
- // Note: This also means that `age` will be excluded from the auto generated equals and hashCode methods.
- // So even though these people have different ages, they are treated as equal.
- // You may find a use case for this, but it is important to be aware of.
- val adam1 = Person("Adam")
- adam1.age = 20
- val adam2 = Person("Adam")
- adam2.age = 50
- println(adam1 == adam2) // true
- println(adam1.hashCode() == adam2.hashCode()) // true
- }
Add Comment
Please, Sign In to add comment