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

 

posted @ 2018-01-07 17:37  trypretty  阅读(6015)  评论(0编辑  收藏  举报