enum和int的相互转换
enum Day{ DAY1, DAY2, DAY3, DAY4, DAY5, DAY6, DAY7 }; public class test { public static void main(String[] args) { System.out.println("enum -> int"); System.out.println("DAY1 = " + Day.DAY1.ordinal()); System.out.println("int -> enum"); System.out.println("5 = " + Day.values()[5]); } }
结果:
enum -> int DAY1 = 0 int -> enum 5 = DAY6