Files
WS-07-Multithreading-Basics…/src/main/java/lecture/hash/User.java
T

34 lines
795 B
Java

package lecture.hash;
public class User {
private int id;
private String name;
public User(int id, String name) {
this.id = id;
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return id == user.id;
}
@Override
public int hashCode() {
return Integer.hashCode(id);
}
public static void main(String[] args) {
User u1 = new User(101, "Ali");
User u2 = new User(101, "Ali");
System.out.println("Are they logically equal? " + u1.equals(u2));
System.out.println("Do they have the same Hash? " + (u1.hashCode() == u2.hashCode()));
}
}