The superclass of all enumerated types. Actual enumeration types inherit from
this class, but extending this class does not make a class an enumeration
type, since the compiler needs to generate special information for it.
| Method from java.lang.Enum Detail: |
protected final Object clone() throws CloneNotSupportedException {
// luni.4C=Enums may not be cloned
throw new CloneNotSupportedException(Messages.getString("luni.4C")); //$NON-NLS-1$
}
{@code Enum} objects are singletons, they may not be cloned. This method
always throws a {@code CloneNotSupportedException}. |
public final int compareTo(E o) {
return ordinal - o.ordinal;
}
Compares this object to the specified enum object to determine their
relative order. This method compares the object's ordinal values, that
is, their position in the enum declaration. |
public final boolean equals(Object other) {
return this == other;
}
Compares this object with the specified object and indicates if they are
equal. In order to be equal, {@code object} must be identical to this
enum constant. |
protected final void finalize() {
// should not have this method
}
All enum classes should not have finalize methods. |
public final Class<E> getDeclaringClass() {
Class< ? > myClass = getClass();
Class< ? > mySuperClass = myClass.getSuperclass();
if (Enum.class == mySuperClass) {
return (Class< E >)myClass;
}
return (Class< E >)mySuperClass;
}
Returns the enum constant's declaring class. |
static T[] getValues(Class<T> enumType) {
try {
Method values = AccessController
.doPrivileged(new PrivilegedExceptionAction< Method >() {
public Method run() throws Exception {
Method valsMethod = enumType.getMethod("values", //$NON-NLS-1$
(Class[]) null);
valsMethod.setAccessible(true);
return valsMethod;
}
});
return (T[]) values.invoke(enumType, (Object[])null);
} catch (Exception e) {
return null;
}
}
|
public final int hashCode() {
return ordinal + (name == null ? 0 : name.hashCode());
}
|
public final String name() {
return name;
}
Returns the name of this enum constant. The name is the field as it
appears in the {@code enum} declaration. |
public final int ordinal() {
return ordinal;
}
Returns the position of the enum constant in the declaration. The first
constant has an ordinal value of zero. |
public String toString() {
return name;
}
Returns a string containing a concise, human-readable description of this
object. In this case, the enum constant's name is returned. |
public static T valueOf(Class<T> enumType,
String name) {
if ((enumType == null) || (name == null)) {
// luni.4D=Argument must not be null
throw new NullPointerException(Messages.getString("luni.4D")); //$NON-NLS-1$
}
T[] values = getValues(enumType);
if (values == null) {
// luni.4E={0} is not an enum type
throw new IllegalArgumentException(Messages.getString("luni.4E", enumType)); //$NON-NLS-1$
}
for (T enumConst : values) {
if (enumConst.name.equals(name)) {
return enumConst;
}
}
// luni.4F={0} is not a constant in the enum type {1}
throw new IllegalArgumentException(Messages.getString("luni.4F", name, //$NON-NLS-1$
enumType));
}
Returns the constant with the specified name of the specified enum type. |