feat: Add comprehensive examples from multithreading and hashing lectures
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user