-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyClass.java
More file actions
37 lines (31 loc) · 817 Bytes
/
Copy pathMyClass.java
File metadata and controls
37 lines (31 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package hash;
public class MyClass {
private Long id;
private String name;
public MyClass(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public String getName() {
return name;
}
public boolean equals(Object object) {
System.out.println("Equals is called:" + this + " : " + object);
MyClass other = (MyClass) object;
return id.equals(other.id) && name.equals(other.name);
}
public int hashCode() {
System.out.println("HashCode is called:" + this);
return id.intValue();
}
@Override
public String toString() {
return "MyClass{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}