java.lang
Class Enum<T extends Enum<T>>

java.lang.Object
  extended by java.lang.Enum<T>
All Implemented Interfaces:
Serializable, Comparable<T>

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

This class represents a Java enumeration. All enumerations are subclasses of this class.

Since:
1.5
See Also:
Serialized Form

Constructor Summary
protected Enum(String name, int ordinal)
          This constructor is used by the compiler to create enumeration constants.
 
Method Summary
protected  Object clone()
          Cloning of enumeration constants is prevented, to maintain their singleton status.
 int compareTo(T e)
          Returns an integer which represents the relative ordering of this enumeration constant.
 boolean equals(Object o)
          Returns true if this enumeration is equivalent to the supplied object, o.
protected  void finalize()
          Enumerations can not have finalization methods.
 Class<T> getDeclaringClass()
          Returns the type of this enumeration constant.
 int hashCode()
          Returns the hash code of this constant.
 String name()
          Returns the name of this enumeration constant.
 int ordinal()
          Returns the number of this enumeration constant, which represents the order in which it was originally declared, starting from zero.
 String toString()
          Returns a textual representation of this enumeration constant.
static
<S extends Enum<S>>
S
valueOf(Class<S> etype, String s)
          Returns an Enum for a enum class given a description string of the enum constant.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Enum

protected Enum(String name,
               int ordinal)
This constructor is used by the compiler to create enumeration constants.

Parameters:
name - the name of the enumeration constant.
ordinal - the number of the enumeration constant, based on the declaration order of the constants and starting from zero.
Method Detail

valueOf

public static <S extends Enum<S>> S valueOf(Class<S> etype,
                                            String s)
Returns an Enum for a enum class given a description string of the enum constant.

Throws:
NullPointerException - when etype or s are null.
IllegalArgumentException - when there is no value s in the enum etype.

equals

public final boolean equals(Object o)
Returns true if this enumeration is equivalent to the supplied object, o. Only one instance of an enumeration constant exists, so the comparison is simply done using ==.

Overrides:
equals in class Object
Parameters:
o - the object to compare to this.
Returns:
true if this == o.
See Also:
Object.hashCode()

hashCode

public final int hashCode()
Returns the hash code of this constant. This is simply the ordinal.

Overrides:
hashCode in class Object
Returns:
the hash code of this enumeration constant.
See Also:
Object.equals(Object), System.identityHashCode(Object)

toString

public String toString()
Returns a textual representation of this enumeration constant. By default, this is simply the declared name of the constant, but specific enumeration types may provide an implementation more suited to the data being stored.

Overrides:
toString in class Object
Returns:
a textual representation of this constant.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)

compareTo

public final int compareTo(T e)
Returns an integer which represents the relative ordering of this enumeration constant. Enumeration constants are ordered by their ordinals, which represents their declaration order. So, comparing two identical constants yields zero, while one declared prior to this returns a positive integer and one declared after yields a negative integer.

Specified by:
compareTo in interface Comparable<T extends Enum<T>>
Parameters:
e - the enumeration constant to compare.
Returns:
a negative integer if e.ordinal < this.ordinal, zero if e.ordinal == this.ordinal and a positive integer if e.ordinal > this.ordinal.
Throws:
ClassCastException - if e is not an enumeration constant of the same class.

clone

protected final Object clone()
                      throws CloneNotSupportedException
Cloning of enumeration constants is prevented, to maintain their singleton status.

Overrides:
clone in class Object
Returns:
the cloned object.
Throws:
CloneNotSupportedException - as enumeration constants can't be cloned.
See Also:
Cloneable

name

public final String name()
Returns the name of this enumeration constant.

Returns:
the name of the constant.

ordinal

public final int ordinal()
Returns the number of this enumeration constant, which represents the order in which it was originally declared, starting from zero.

Returns:
the number of this constant.

getDeclaringClass

public final Class<T> getDeclaringClass()
Returns the type of this enumeration constant. This is the class corresponding to the declaration of the enumeration.

Returns:
the type of this enumeration constant.

finalize

protected final void finalize()
Enumerations can not have finalization methods.

Overrides:
finalize in class Object
Since:
1.6
See Also:
System.gc(), System.runFinalizersOnExit(boolean), java.lang.ref