|
//枚举类定义
public enum Sample {
SAMP1, SAMP2, SAMP3, SAMP4;
public String getSamp(){
switch(this) {
case SAMP1:
return "samp1";
case SAMP2:
return "samp2";
case SAMP3:
return "samp3";
case SAMP4:
return "samp4";
default :
return "other";
}
}
}
//枚举类测试
public class TestSample {
public static void main(String[] args) {
/*System.out.println(Sample.values().length);
System.out.println(Sample.SAMP1.getSamp());*/
for(int i=0; i<Sample.values().length; i++){
System.out.println(Sample.values().getSamp());
}
}
} |
|