- Day day = Day.MONDAY;
- //获取对象所代表的那个枚举类型的值
- System.out.println(day.name()); //MONDAY
- //当前枚举常量在所定义的枚举类型中所在的位置
- System.out.println("ordinal: "+ day.ordinal()); //1
- //比较是否类型与值都相同
- System.out.println(day.equals("MONDAY")); //false
- System.out.println("hashcode:"+ day.hashCode());
- //比较同一个Enum中的数据的顺序。顺序比参数大则为正数,小为负数,相同为0.返回值就是位置相差的的个数
- System.out.println("compareTo: "+ day.compareTo(Day.SATURDAY));//-5
- //获得枚举对象的类
- System.out.println(day.getDeclaringClass());