Created
June 26, 2017 18:12
-
-
Save dharmakshetri/37a13ec080dc89eb44ced417857a510c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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