E
- The type of the enum subclassSerializable
, Comparable<E>
, Constable
public abstract class Enum<E extends Enum<E>> extends Object implements Constable, Comparable<E>, Serializable
serialVersionUID
; see the Java Object Serialization Specification for details. Note that when using an enumeration type as the type of a set or as the type of the keys in a map, specialized and efficient set and map implementations are available.
Modifier and Type | Class | Description |
---|---|---|
static final class |
Enum.EnumDesc<E extends Enum<E>> |
A nominal descriptor for an enum constant. |
Modifier | Constructor | Description |
---|---|---|
protected |
Sole constructor. |
Modifier and Type | Method | Description |
---|---|---|
protected final Object |
clone() |
Throws CloneNotSupportedException. |
final int |
compareTo |
Compares this enum with the specified object for order. |
final Optional |
describeConstable() |
Returns an enum descriptor EnumDesc for this instance, if one can be constructed, or an empty Optional if one cannot be. |
final boolean |
equals |
Returns true if the specified object is equal to this enum constant. |
protected final void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization has been deprecated for removal. |
final Class |
getDeclaringClass() |
Returns the Class object corresponding to this enum constant's enum type. |
final int |
hashCode() |
Returns a hash code for this enum constant. |
final String |
name() |
Returns the name of this enum constant, exactly as declared in its enum declaration. |
final 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 |
Returns the enum constant of the specified enum class with the specified name. |
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 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()
EnumSet
and EnumMap
.public String toString()
public final boolean equals(Object other)
public final int hashCode()
protected final Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- if the object's class does not support the Cloneable
interface. Subclasses that override the clone
method can also throw this exception to indicate that an instance cannot be cloned.public final int compareTo(E o)
compareTo
in interface Comparable<E extends Enum<E>>
o
- the object to be compared.public final Class<E> getDeclaringClass()
Object.getClass()
method for enum constants with constant-specific class bodies.)public final Optional<Enum.EnumDesc<E>> describeConstable()
EnumDesc
for this instance, if one can be constructed, or an empty Optional
if one cannot be.describeConstable
in interface Constable
Optional
containing the resulting nominal descriptor, or an empty Optional
if one cannot be constructed.public static <T extends Enum<T>> T valueOf(Class<T> enumClass, String name)
Note that for a particular enum class T
, the implicitly declared public static T valueOf(String)
method on that enum may be used instead of this method to map from a name to the corresponding enum constant. All the constants of an enum class can be obtained by calling the implicit public static T[] values()
method of that class.
T
- The enum class whose constant is to be returnedenumClass
- the Class
object of the enum class from which to return a constantname
- the name of the constant to returnIllegalArgumentException
- if the specified enum class has no constant with the specified name, or the specified class object does not represent an enum classNullPointerException
- if enumClass
or name
is null@Deprecated(since="18", forRemoval=true) protected final void finalize()
Object.finalize()
for background information and details about migration options.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Enum.html