java.lang.Enum

android/adt-bundle/sdk/docs/reference/java/lang/Enum.html



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

Class Overview


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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Comparable

Protected Constructors


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

Constructor for constants of enum subtypes.

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

Public Methods


public final int compareTo (E o)
Added in API level 1

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
othe 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 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
  • Comparable
public final boolean equals (Object other)
Added in API level 1

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
otherthe object to compare this enum constant with.
Returns
  • true if the specified object is equal to this Enum; false otherwise.
public final Class<E> getDeclaringClass ()
Added in API level 1

Returns the enum constant's declaring class.

Returns
  • the class object representing the constant's enum type.
public final int hashCode ()
Added in API level 1

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
  • this object's hash code.
public final String name ()
Added in API level 1

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

Returns
  • the name of this enum constant.
See Also
  • toString()
public final int ordinal ()
Added in API level 1

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.
public String toString ()
Added in API level 1

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

Returns
  • a printable representation of this object.
public static T valueOf (Class<T> enumType, String name)
Added in API level 1

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

Parameters
enumTypethe class of the enumerated type to search for the constant value.
namethe name of the constant value to find.
Returns
  • the enum constant.
Throws
NullPointerExceptionif either enumType or name are null.
IllegalArgumentExceptionif enumType is not an enumerated type or does not have a constant value called name.

Protected Methods


protected final Object clone ()
Added in API level 1

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

Returns
  • does not return.
Throws
CloneNotSupportedExceptionis always thrown.
protected final void finalize ()
Added in API level 1

Enum types may not have finalizers.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值