E - The enum type subclasspublic abstract class SoftEnum<E extends SoftEnum<E>> extends Object implements Comparable<E>, Serializable
Enum
and is intended as common base class of classes we shall call 'soft enums'.
While soft enums are ordinary classes and lack all support
special to enumeration types,
they are also not subject to the restrictions that come with them.
It is the programmer who is responsible for implementing soft enums in a proper way.
As enumeration types
are implicitely final subclasses of Enum,
'soft enums' are derived from SoftEnum
and shall be final except if constants overwrite methods.
A 'soft enum' shall have no instances
other than those defined by its enum constants.
More information about enums, including descriptions of the
implicitly declared methods synthesized by the compiler, can be
found in section 8.9 of
The Java™ Language Specification.
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.
Class.getEnumConstants(),
EnumSet,
EnumMap,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
private String |
name
The name of this enum constant, as declared in the enum declaration.
|
private int |
ordinal
The ordinal of this enumeration constant (its position
in the enum declaration, where the initial constant is assigned
an ordinal of zero).
|
private static long |
serialVersionUID |
| Modifier | Constructor and Description |
|---|---|
protected |
SoftEnum(String name,
int ordinal)
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
SoftEnum<E> |
clone()
Throws CloneNotSupportedException.
|
int |
compareTo(E obj)
Compares this enum with the specified object for order.
|
boolean |
equals(Object other)
Returns true if the specified object is equal to this
enum constant.
|
protected void |
finalize()
enum classes cannot have finalize methods.
|
Class<?> |
getDeclaringClass()
Returns the Class object corresponding to this enum constant's
enum type.
|
int |
hashCode()
Returns a hash code for this enum constant.
|
String |
name()
Returns the name of this enum constant, exactly as declared in its
enum declaration.
|
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).
|
private void |
readObject(ObjectInputStream stream)
Prevent default deserialization.
|
private void |
readObjectNoData() |
String |
toString()
Returns the name of this enum constant, as contained in the
declaration.
|
private static final long serialVersionUID
private final String name
toString() method rather than
accessing this field.private final int ordinal
protected SoftEnum(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 final String toString()
public final boolean equals(Object other)
public final int hashCode()
public final SoftEnum<E> clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic final int compareTo(E obj)
compareTo in interface Comparable<E extends SoftEnum<E>>public final Class<?> getDeclaringClass()
Object.getClass() method for enum constants with
constant-specific class bodies.)protected final void finalize()
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionprivate void readObjectNoData()
throws ObjectStreamException
ObjectStreamExceptionCopyright © 2012–2018 Simuline Organization (l2r). All rights reserved.