Java 1.5 supports the use of enumerated types, ; these enums look just like their C and C++ counterparts. But, in the Java programming language, enums are far more powerful than their counterparts in other languages, which are little more than glorified integers. In Java, all enums have an ordinal()
method, which returns the numerical position of each enum constant in its class declaration.
Java Language Specification, in Section 8.9, "Enums" does not specify the use of ordinal()
in programs. Improper However, improper use of ordinal()
method in program logic can cause errors in programs.
Wiki Markup |
---|
According to the Java API \[[API 2006|AA. Bibliography#API 06]\], {{ordinal()}} is defined as: {{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
.
...
C Secure Coding Standard: INT09-C. Ensure enumeration constants map to unique values
C++ Secure Coding Standard: INT09-CPP. Ensure enumeration constants map to unique values
...