Yes you can use the Enum.values()
method to get an array of Enum values then use the length
property.
public class Main {
enum WORKDAYS { Monday, Tuesday, Wednesday, Thursday, Friday; }
public static void main(String[] args) {
System.out.println(WORKDAYS.values().length);
// prints 5
}
}
http://ideone.com/zMB6pG
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…