-
Bug
-
Resolution: Not an Issue
-
P2
-
None
-
6
-
generic
-
generic
There is an JLS3 statement (8.9 Enums):
"It follows that enum type declarations cannot contain fields that conflict with the enum constants, and cannot contain methods that conflict with the automatically generated methods (values() and valueOf(String)) or methods that override the final methods in Enum: (equals(Object), hashCode(), clone(), compareTo(Object), name(), ordinal(), and getDeclaringClass())."
As I understand, javac should report error, if we define such fields or methods.
Actually it does report compile-time error for all these, except compareTo(Object).
For example:
enum TestEnum {
a1, a2, a3;
public void compareTo(Object obj) {
}
}
no problem is reported by javac.
"It follows that enum type declarations cannot contain fields that conflict with the enum constants, and cannot contain methods that conflict with the automatically generated methods (values() and valueOf(String)) or methods that override the final methods in Enum: (equals(Object), hashCode(), clone(), compareTo(Object), name(), ordinal(), and getDeclaringClass())."
As I understand, javac should report error, if we define such fields or methods.
Actually it does report compile-time error for all these, except compareTo(Object).
For example:
enum TestEnum {
a1, a2, a3;
public void compareTo(Object obj) {
}
}
no problem is reported by javac.
- relates to
-
JDK-6393539 CONFORMANCE: no compiler error if method in annotation type is override-equivalent to clone(), etc.
-
- Closed
-