Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Enum

public abstract class Enum
extends Object implements Serializable, Comparable<E extends Enum<E>>

java.lang.Object
   ↳ java.lang.Enum<E extends java.lang.Enum<E>>
Known Direct Subclasses


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.

Summary

Protected constructors

Enum(String name, int ordinal)

Constructor for constants of enum subtypes.

Public methods

final int compareTo(E o)

Compares this object to the specified enum object to determine their relative order.

final boolean equals(Object other)

Compares this object with the specified object and indicates if they are equal.

final Class<E> getDeclaringClass()

Returns the enum constant's declaring class.

final int hashCode()

Returns an integer hash code for this object.

final String name()

Returns the name of this enum constant.

final 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>> T valueOf(Class<T> enumType, String name)

Returns the constant with the specified name of the specified enum type.

Protected methods

final Object clone()

Enum objects are singletons, they may not be cloned.

final void finalize()

Enum types may not have finalizers.

Inherited methods

From class java.lang.Object
From interface java.lang.Comparable

Protected constructors

Enum

Added in API level 1
Enum (String name, 
                int ordinal)

Constructor for constants of enum subtypes.

Parameters
name String: the enum constant's declared name.
ordinal int: the enum constant's ordinal, which corresponds to its position in the enum declaration, starting at zero.

Public methods

compareTo

Added in API level 1
int compareTo (E o)

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.

Parameters
o E: the enum object to compare this object to.
Returns
int 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 and o are equal; a positive value if the ordinal value of this enum constant is greater than the ordinal value of o.

See also:

equals

Added in API level 1
boolean equals (Object other)

Compares this object with the specified object and indicates if they are equal. In order to be equal, object must be identical to this enum constant.

Parameters
other Object: the object to compare this enum constant with.
Returns
boolean true if the specified object is equal to this Enum; false otherwise.

getDeclaringClass

Added in API level 1
Class<E> getDeclaringClass ()

Returns the enum constant's declaring class.

Returns
Class<E> the class object representing the constant's enum type.

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(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.

Returns
int this object's hash code.

name

Added in API level 1
String name ()

Returns the name of this enum constant. The name is the field as it appears in the enum declaration.

Returns
String the name of this enum constant.

See also:

ordinal

Added in API level 1
int ordinal ()

Returns the position of the enum constant in the declaration. The first constant has an ordinal value of zero.

Returns
int the ordinal value of this enum constant.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. In this case, the enum constant's name is returned.

Returns
String a printable representation of this object.

valueOf

Added in API level 1
T valueOf (Class<T> enumType, 
                String name)

Returns the constant with the specified name of the specified enum type.

Parameters
enumType Class: the class of the enumerated type to search for the constant value.
name String: the name of the constant value to find.
Returns
T the enum constant.
Throws
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.

Protected methods

clone

Added in API level 1
Object clone ()

Enum objects are singletons, they may not be cloned. This method always throws a CloneNotSupportedException.

Returns
Object does not return.
Throws
CloneNotSupportedException is always thrown.

finalize

Added in API level 1
void finalize ()

Enum types may not have finalizers.

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.