加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090217132918/http://developer.android.com:80/reference/java/lang/Enum.html
public abstract class

Enum

extends Object
implements Serializable Comparable<T>
java.lang.Object
   ↳ java.lang.Enum<E extends java.lang.Enum<E>>
Known Direct Subclasses

Class Overview

The superclass of all enumerated types.

Summary

Protected Constructors
Enum(String name, int ordinal)
Constructor for enum subtypes.
Public Methods
final int compareTo(E o)
Returns the comparative ordering of the receiver and the given argument.
final boolean equals(Object other)
Returns true only if the receiver is equal to the argument.
final Class<E> getDeclaringClass()
Returns the enum constant's declaring class.
final int hashCode()
Returns the hash of the receiver.
final String name()
Returns the name of the enum constant.
final int ordinal()
Returns the position of the enum constant in the declaration.
String toString()
Answer a string representation of the receiver suitable for display to a programmer.
static <T extends Enum<T>> T valueOf(Class<T> enumType, String name)
Returns the named constant of the given enum type.
Protected Methods
final Object clone()
Enums are singletons, they may not be cloned.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Comparable

Protected Constructors

protected Enum (String name, int ordinal)

Constructor for enum subtypes.

Parameters
name the enum constant declared name.
ordinal the enum constant position ordinal.

Public Methods

public final int compareTo (E o)

Returns the comparative ordering of the receiver and the given argument. If the receiver is naturally ordered before the actual argument then the result is negative, if the receiver is naturally ordered in equal position to the actual argument then the result is zero, and if the receiver is naturally ordered after the actual argument then the result is positive.

Returns
  • negative, zero, or positive value depending upon before, equal, or after natural order respectively.
See Also

public final boolean equals (Object other)

Returns true only if the receiver is equal to the argument. Since enums are unique this is equivalent to an identity test.

Parameters
other Object the object to compare with this object.
Returns
  • true if the receiver and argument are equal, otherwise return false.

public final Class<E> getDeclaringClass ()

Returns the enum constant's declaring class.

Returns
  • the class object representing the constant's enum type.

public final int hashCode ()

Returns the hash of the receiver.

Returns
  • the hash code.

public final String name ()

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

Returns
  • the precise enum constant name.
See Also

public final int ordinal ()

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

Returns
  • the constant's ordinal value.

public String toString ()

Answer a string representation of the receiver suitable for display to a programmer.

Returns
  • the displayable string name.

public static T valueOf (Class<T> enumType, String name)

Returns the named constant of the given 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 either the enumType or name are null.
IllegalArgumentException if enumType is not an enumerated type or does not have a constant value called name.

Protected Methods

protected final Object clone ()

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

Returns
  • does not return.