Package java.lang
Class Enum<E extends Enum<E>>
java.lang.Object
java.lang.Enum<E>
- All Implemented Interfaces:
Serializable,Comparable<E>
public abstract class Enum<E extends Enum<E>> extends Object implements Serializable, Comparable<E>
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.
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description protected Objectclone()Enumobjects are singletons, they may not be cloned.intcompareTo(E o)Compares this object to the specified enum object to determine their relative order.booleanequals(Object other)Compares this object with the specified object and indicates if they are equal.protected voidfinalize()Enum types may not have finalizers.Class<E>getDeclaringClass()Returns the enum constant's declaring class.static <T extends Enum<T>>
T[]getSharedConstants(Class<T> enumType)Returns a shared, mutable array containing the constants of this enum.inthashCode()Returns an integer hash code for this object.Stringname()Returns the name of this enum constant.intordinal()Returns the position of the enum constant in the declaration.StringtoString()Returns a string containing a concise, human-readable description of this object.static <T extends Enum<T>>
TvalueOf(Class<T> enumType, String name)Returns the constant with the specified name of the specified enum type.
-
Constructor Details
-
Enum
Constructor for constants of enum subtypes.- Parameters:
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.
-
-
Method Details
-
name
Returns the name of this enum constant. The name is the field as it appears in theenumdeclaration.- Returns:
- the name of this enum constant.
- See Also:
toString()
-
ordinal
public final int ordinal()Returns the position of the enum constant in the declaration. The first constant has an ordinal value of zero.- Returns:
- the ordinal value of this enum constant.
-
toString
Returns a string containing a concise, human-readable description of this object. In this case, the enum constant's name is returned. -
equals
Compares this object with the specified object and indicates if they are equal. In order to be equal,objectmust be identical to this enum constant.- Overrides:
equalsin classObject- Parameters:
other- the object to compare this enum constant with.- Returns:
trueif the specified object is equal to thisEnum;falseotherwise.- See Also:
Object.hashCode()
-
hashCode
public final int hashCode()Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually 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
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
clone
Enumobjects are singletons, they may not be cloned. This method always throws aCloneNotSupportedException.- Overrides:
clonein classObject- Returns:
- does not return.
- Throws:
CloneNotSupportedException- is always thrown.
-
compareTo
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.- Specified by:
compareToin interfaceComparable<E extends Enum<E>>- Parameters:
o- the enum object to compare this object to.- Returns:
- a negative value if the ordinal value of this enum constant is
less than the ordinal value of
o; 0 if the ordinal values of this enum constant andoare equal; a positive value if the ordinal value of this enum constant is greater than the ordinal value ofo. - See Also:
Comparable
-
getDeclaringClass
Returns the enum constant's declaring class.- Returns:
- the class object representing the constant's enum type.
-
valueOf
Returns the constant with the specified name of the specified enum type.- Parameters:
enumType- the class of the enumerated type to search for the constant value.name- the name of the constant value to find.- Returns:
- the enum constant.
- Throws:
NullPointerException- if eitherenumTypeornamearenull.IllegalArgumentException- ifenumTypeis not an enumerated type or does not have a constant value calledname.
-
finalize
protected final void finalize()Enum types may not have finalizers.
-