throw ClassCastException if asked to compare Enums of different types

This commit is contained in:
Joel Dice 2009-08-21 16:06:12 -06:00
parent 4536f13ee4
commit 77ae259e41

View File

@ -22,6 +22,10 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
}
public int compareTo(E other) {
if (getDeclaringClass() != other.getDeclaringClass()) {
throw new ClassCastException();
}
return ordinal - other.ordinal;
}