枚举类的使用,有构造函数,有函数哟
package com.bird.test; import org.junit.Test; public class EumeTest { @Test public void print() { String day; day = Week.MON.getValue(); System.out.println(day + Week.MON.getValue1()); } } enum Week { MON("星期一") { public String getValue1() { return "this is the first day."; } }, TUE("星期二") { public String getValue1() { return "this is the first day."; } }, WED("星期三") { public String getValue1() { return "this is the first day."; } }, THU("星期四"){ public String getValue1() { return "this is the first day."; } }, FRI("星期五"){ public String getValue1() { return "this is the first day."; } }, SAT("星期六"){ public String getValue1() { return "this is the first day."; } }, SUN("星期日"){ public String getValue1() { return "this is the first day."; } }; private String value; private Week(String value) { this.value = value; } public String getValue() { return value; } public abstract String getValue1(); }
运行结果:
星期一this is the first day.