Developing Enumerated Types
With Examples in Java |
Prof. David Bernstein
|
Computer Science Department |
bernstdh@jmu.edu |
Though it is not immediately obvious from the documentation for the Java API, all enumerated types have the following methods "implemented for them".
values()
returns an array containing
all of the objects in the setvalueOf(String)
returns the instance with the
specified identifier (or throws
IllegalArgumentException
)int compareTo(E other)
which uses the order
of the elementsboolean equals(E other)
ordinal()
returns the ordinal value of the instance
(0-based)toString()
returns a String
representation of the identifierpublic static final String
Objects:
public static final String
Objects:
public static final int
Values: