Java language enumeration types have an ordinal()
method that returns the numerical position of each enumeration constant in its class declaration.
The _Java Language Specification_ \[ [JLS 2005|AA. References#JLS 05]\] [§8] §8.9, "Enums,"|http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9] does not specify the use of {{ Wiki Markup ordinal()
}} in programs. However, using the {{ordinal()
}} method to derive the value associated with an {{enum
}} constant is error prone and should be avoided. unmigrated-wiki-markup
According to the Java API \[ [API 2006|AA. References#API 06]\], {{public
final
int
ordinal()
}}:
Returns the ordinal of the enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero). Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures, such as
EnumSet
andEnumMap
.
...
INT09-CPP. Ensure enumeration constants map to unique values<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="97a439af-327c-45d6-bf65-e341b4dd67bb"><ac:plain-text-body><![CDATA[ | |||
http://www.aitcnet.org/isai/] | "Enumerator Issues [java:CCB]" | ]]></ac:plain-text-body></ac:structured-macro> |
Bibliography
...
[[JLS 2005AA. References#JLS 05]] | http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9] | |
]]></ac:plain-text-body></ac:structured-macro> | <ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d8e34f64-c4ff-43ef-8832-ea89166041a4"><ac:plain-text-body><![CDATA[[[API 2006AA. References#API 06]] [Enum | http://download.oracle.com/javase/6/docs/api/java/lang/Enum.html]]]></ac:plain-text-body></ac:structured-macro> |
...
DCL54-J. Enable compile-time type checking of varargs types 01. Declarations and Initialization (DCL) DCL02-J. Declare all enhanced for statement loop variables final