标签:ati test Stub lang eth err ack 获取 esc
JDK1.5新增的enum关键字用于定义枚举类。
枚举类和普通类的区别:
JDK1.5中可以在switch表达式中使用枚举类的对象作为表达式,case子句可以直接使用枚举值的名字,无需添加枚举类作为限定。
若枚举只有一个成员,则可以作为一种单例模式的实现方式。
package anno; public class Test { public static void main(String[] args) { //这里获取一个Season对象 Season spring = Season.SPRING; spring.showInfo(); Season summer = Season.SUMMER; summer.showInfo(); Season autumn = Season.AUTUMN; autumn.showInfo(); Season winter = Season.WINTER; winter.showInfo(); spring.test(); //每次执行Season.SPRING获得的都是一个相同的对象,是一种单例模式 Season spring1 = Season.SPRING; System.out.println(spring==spring1); } } enum Season implements Tmp{ //这里相当于调用有参的私有构造方法 SPRING("春天","春暖花开"), SUMMER("夏天","炎炎夏日"), AUTUMN("秋天","秋高气爽"), WINTER("冬天","寒风凌冽"); private final String NAME; private final String DESC; private Season(String NAME, String DESC) { this.NAME = NAME; this.DESC = DESC; } public void showInfo() { System.out.println(this.NAME+":"+this.DESC); } @Override public void test() { // TODO Auto-generated method stub System.out.println("这是实现Tmp的方法"); } } interface Tmp{ void test(); }
标签:ati test Stub lang eth err ack 获取 esc
原文地址:https://www.cnblogs.com/xiximayou/p/12063548.html