Is there a a C-like way to get item number from enum in java?

前端 未结 5 1708
甜味超标
甜味超标 2020-12-16 21:19

Perhap this is a simple basic question

Having an enum

public enum TK{
        ID,GROUP,DATA,FAIL;
        }

Can I get the order num

5条回答
  •  醉酒成梦
    2020-12-16 22:10

    http://java.sun.com/javase/6/docs/api/java/lang/Enum.html#ordinal()

    public final 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). Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures, such as EnumSet and EnumMap.

提交回复
热议问题