author | duke |
Wed, 05 Jul 2017 18:59:39 +0200 | |
changeset 18044 | f1a01fb5f958 |
parent 16333 | a6e1ded87200 |
permissions | -rw-r--r-- |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
1 |
/* |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
2 |
* @test /nodynamiccopyright/ |
16333 | 3 |
* @bug 6563143 8008436 8009138 |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
4 |
* @summary javac should issue a warning for overriding equals without hashCode |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
5 |
* @summary javac should not issue a warning for overriding equals without hasCode |
16333 | 6 |
* @summary javac, equals-hashCode warning tuning |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
7 |
* if hashCode has been overriden by a superclass |
16333 | 8 |
* @compile/ref=EqualsHashCodeWarningTest.out -Xlint:overrides -XDrawDiagnostics EqualsHashCodeWarningTest.java |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
9 |
*/ |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
10 |
|
16333 | 11 |
import java.util.Comparator; |
12 |
||
13 |
public class EqualsHashCodeWarningTest { |
|
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
14 |
@Override |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
15 |
public boolean equals(Object o) { |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
16 |
return o == this; |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
17 |
} |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
18 |
|
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
19 |
@Override |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
20 |
public int hashCode() { |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
21 |
return 0; |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
22 |
} |
16333 | 23 |
|
24 |
public Comparator m() { |
|
25 |
return new Comparator() { |
|
26 |
@Override |
|
27 |
public boolean equals(Object o) {return true;} |
|
28 |
||
29 |
@Override |
|
30 |
public int compare(Object o1, Object o2) { |
|
31 |
return 0; |
|
32 |
} |
|
33 |
}; |
|
34 |
} |
|
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
35 |
} |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
36 |
|
16333 | 37 |
class SubClass extends EqualsHashCodeWarningTest { |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
38 |
@Override |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
39 |
public boolean equals(Object o) { |
16333 | 40 |
return true; |
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
41 |
} |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
42 |
} |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
43 |
|
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
44 |
@SuppressWarnings("overrides") |
16333 | 45 |
class DontWarnMe { |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
46 |
@Override |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
47 |
public boolean equals(Object o) { |
16333 | 48 |
return true; |
16301
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
49 |
} |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
50 |
} |
b6fd735ea78e
6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff
changeset
|
51 |
|
16320
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
52 |
class DoWarnMe { |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
53 |
@Override |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
54 |
public boolean equals(Object o) { |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
55 |
return o == this; |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
56 |
} |
92ba27b7aaf3
8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents:
16301
diff
changeset
|
57 |
} |
16333 | 58 |
|
59 |
abstract class IamAbstractGetMeOutOfHere { |
|
60 |
public boolean equals(Object o){return true;} |
|
61 |
} |
|
62 |
||
63 |
interface I { |
|
64 |
public boolean equals(Object o); |
|
65 |
} |
|
66 |
||
67 |
enum E { |
|
68 |
A, B |
|
69 |
} |
|
70 |
||
71 |
@interface anno {} |