Is there a a C-like way to get item number from enum in java ?
Posted
by Hernán Eche
on Stack Overflow
See other posts from Stack Overflow
or by Hernán Eche
Published on 2010-05-04T13:29:45Z
Indexed on
2010/05/04
13:38 UTC
Read the original article
Hit count: 232
Perhap this is a simple basic question
Having an enum
public enum TK{
ID,GROUP,DATA,FAIL;
}
Can I get the order number for example ID=0, GROUP=2, DATA=3, FAIL=4 ?
This is a way to to that, but a weird and long one! =S
public enum TK{
ID(0),GROUP(1),DATA(2),FAIL(3);
int num;
TK(int n)
{
this.num=n;
}
public int get()
{
return num;
}
};
to get numbers so I write TK.ID.get(), TK.GROUP.get(), etc... I don't like that
there is a better way?
( C enums, C macros..I miss you both )
thanks
© Stack Overflow or respective owner