E
- The enum type subclasspublic abstract class Enum<E extends Enum<E>> extends Object implements Comparable<E>, Serializable
Modifier | Constructor and Description |
---|---|
protected |
Enum(String name,
int ordinal)
Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(E o)
Compares this enum with the specified object for order.
|
boolean |
equals(Object other)
Returns true if the specified object is equal to this enum constant.
|
int |
hashCode()
Returns a hash code for this enum constant.
|
String |
name()
Returns the name of this enum constant, exactly as declared in its enum declaration.
|
int |
ordinal()
Returns the ordinal of this enumeration constant (its position in its enum declaration, where the
initial constant is assigned an ordinal of zero).
|
String |
toString()
Returns the name of this enum constant, as contained in the declaration.
|
static <T extends Enum<T>> |
valueOf(Class<T> enumType,
String name)
This method is available for compilation purpose.
|
protected Enum(String name, int ordinal)
name
- - The name of this enum constant, which is the identifier used to declare it.ordinal
- - The ordinal of this enumeration constant (its position in the enum declaration, where
the initial constant is assigned an ordinal of zero).public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
T
- the enum type whose constant is to be returnedenumType
- the Class object of the enum type from which to return a constantname
- the name of the constant to returnNoSuchMethodError
- alwayspublic final int compareTo(E o)
compareTo
in interface Comparable<E extends Enum<E>>
o
- the object to be compared.public final boolean equals(@Nullable Object other)
equals
in class Object
other
- the object to be compared for equality with this object.Object.hashCode()
,
HashMap
public final int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public final String name()
toString()
method in preference to this one, as the
toString method may return a more user-friendly name. This method is designed primarily for
use in specialized situations where correctness depends on getting the exact name, which will not
vary from release to release.public final int ordinal()
public String toString()