枚举
/*
* 通过JDK5提供的枚举来做枚举类
*/
public enumDirection2 {
FRONT("前"), BEHIND("后"), LEFT("左"), RIGHT("右");
private String name;
private Direction2(String name){
this.name = name;
}
public String getName() {
return name;
}
}
public classDirectionDemo {
public static void main(String[] args) {
Direction2d2 = Direction2.FRONT;
System.out.println(d2);
System.out.println(d2.getName());
System.out.println("-------------");
}
}
运行结果:
FRONT
前
-------------