forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
40 lines (34 loc) · 751 Bytes
/
Test.java
File metadata and controls
40 lines (34 loc) · 751 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
38
39
40
class Super {
protected int myInt = 1;
public boolean equals(Object other) {
if (other == null)
return false;
if (other.getClass() != getClass())
return false;
if (myInt != ((Super)other).myInt)
return false;
return true;
}
public int hashCode() {
return myInt;
}
}
class NoEquals extends Super {
// BAD
public int hashCode() {
return myInt+1;
}
}
class NoHashCode extends Super {
// BAD
public boolean equals(Object other) {
return true;
}
}
class RefiningEquals extends Super {
protected long myLong = 1;
// OK: a finer equals than the supertype equals, so the hash code is still valid
public boolean equals(Object other) {
return (super.equals(other) && myLong == ((RefiningEquals)other).myLong);
}
}