public abstract class Enum<E extends Enum<E>> extends Object implements Serializable, Comparable<E>
Modifier | Constructor and Description |
---|---|
protected |
Enum(String name,
int ordinal)
Constructor for constants of enum subtypes.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
clone()
Enum objects are singletons, they may not be cloned. |
int |
compareTo(E o)
Compares this object to the specified enum object to determine their
relative order.
|
boolean |
equals(Object other)
Compares this object with the specified object and indicates if they are
equal.
|
protected void |
finalize()
Enum types may not have finalizers.
|
Class<E> |
getDeclaringClass()
Returns the enum constant's declaring class.
|
static <T extends Enum<T>> |
getSharedConstants(Class<T> enumType)
Returns a shared, mutable array containing the constants of this enum.
|
int |
hashCode()
Returns an integer hash code for this object.
|
String |
name()
Returns the name of this enum constant.
|
int |
ordinal()
Returns the position of the enum constant in the declaration.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static <T extends Enum<T>> |
valueOf(Class<T> enumType,
String name)
Returns the constant with the specified name of the specified enum type.
|
protected Enum(String name, int ordinal)
name
- the enum constant's declared name.ordinal
- the enum constant's ordinal, which corresponds to its position
in the enum declaration, starting at zero.public final String name()
enum
declaration.toString()
public final int ordinal()
public String toString()
public final boolean equals(Object other)
object
must be identical to this
enum constant.equals
in class Object
other
- the object to compare this enum constant with.true
if the specified object is equal to this
Enum
; false
otherwise.Object.hashCode()
public final int hashCode()
Object
Object.equals(java.lang.Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
hashCode
in class Object
Object.equals(java.lang.Object)
protected final Object clone() throws CloneNotSupportedException
Enum
objects are singletons, they may not be cloned. This method
always throws a CloneNotSupportedException
.clone
in class Object
CloneNotSupportedException
- is always thrown.public final int compareTo(E o)
compareTo
in interface Comparable<E extends Enum<E>>
o
- the enum object to compare this object to.o
; 0 if the ordinal
values of this enum constant and o
are equal; a positive
value if the ordinal value of this enum constant is greater than
the ordinal value of o
.Comparable
public final Class<E> getDeclaringClass()
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
enumType
- the class of the enumerated type to search for the constant
value.name
- the name of the constant value to find.NullPointerException
- if either enumType
or name
are null
.IllegalArgumentException
- if enumType
is not an enumerated type or does not
have a constant value called name
.public static <T extends Enum<T>> T[] getSharedConstants(Class<T> enumType)