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

前端 未结 5 1703
甜味超标
甜味超标 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:19

    tk.ordinal()
    

    is the way to do it where tk is an instance of TK

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

提交回复
热议问题