src/share/classes/java/lang/Enum.java
Print this page
*** 171,182 ****
* Enum constants are only comparable to other enum constants of the
* same enum type. The natural order implemented by this
* method is the order in which the constants are declared.
*/
public final int compareTo(E o) {
! Enum other = (Enum)o;
! Enum self = this;
if (self.getClass() != other.getClass() && // optimization
self.getDeclaringClass() != other.getDeclaringClass())
throw new ClassCastException();
return self.ordinal - other.ordinal;
}
--- 171,182 ----
* Enum constants are only comparable to other enum constants of the
* same enum type. The natural order implemented by this
* method is the order in which the constants are declared.
*/
public final int compareTo(E o) {
! Enum<?> other = (Enum<?>)o;
! Enum<E> self = this;
if (self.getClass() != other.getClass() && // optimization
self.getDeclaringClass() != other.getDeclaringClass())
throw new ClassCastException();
return self.ordinal - other.ordinal;
}
*** 191,204 ****
* constant-specific class bodies.)
*
* @return the Class object corresponding to this enum constant's
* enum type
*/
public final Class<E> getDeclaringClass() {
! Class clazz = getClass();
! Class zuper = clazz.getSuperclass();
! return (zuper == Enum.class) ? clazz : zuper;
}
/**
* Returns the enum constant of the specified enum type with the
* specified name. The name must match exactly an identifier used
--- 191,205 ----
* constant-specific class bodies.)
*
* @return the Class object corresponding to this enum constant's
* enum type
*/
+ @SuppressWarnings("unchecked")
public final Class<E> getDeclaringClass() {
! Class<?> clazz = getClass();
! Class<?> zuper = clazz.getSuperclass();
! return (zuper == Enum.class) ? (Class<E>)clazz : (Class<E>)zuper;
}
/**
* Returns the enum constant of the specified enum type with the
* specified name. The name must match exactly an identifier used