Skip to content

Instantly share code, notes, and snippets.

@dharmakshetri
Created June 26, 2017 18:12
Show Gist options
  • Save dharmakshetri/37a13ec080dc89eb44ced417857a510c to your computer and use it in GitHub Desktop.
Save dharmakshetri/37a13ec080dc89eb44ced417857a510c to your computer and use it in GitHub Desktop.
val user1 = User("john", 12345)
val user2 = User("john", 123451)
val user3 = User("john", 12345)
println("==")
println(user1==user2)
println(user1==user3)
println(" euquals")
println(user1.equals(user2))
println(user1.equals(user3))
println("toString")
println(user1.toString())
println("hashCode")
println(user1.hashCode())
class User(val name:String, val code:Int){
override fun equals(other: Any?): Boolean {
if(other == null || other !is User)
return false
return name == other.name && code==other.code
}
override fun hashCode(): Int =
name.hashCode() * 31+code
override fun toString(): String {
return "Client(name=$name, code=$code"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment