枚举
package com.yal.thread1;
public class enumTest {
public static void main(String[] args) {
//toString方法
System.out.println(season.spring.toString());
System.out.println("******");
//values方法
season[] values = season.values();
for(int i=0;i<values.length;i++){
System.out.println(values[i]);
}
//valueof方法
season s = season.valueOf("winter");
System.out.println(s.id);
//关于实现接口
season.spring.show();
season.summer.show();
season.autumn.show();
season.winter.show();
}
}
interface test{
void show();
}
enum season implements test{
spring("春",1){
@Override
public void show() {
System.out.println("c");
}
},
summer("夏",2){
@Override
public void show() {
System.out.println("x");
}
},
autumn("秋",3){
@Override
public void show() {
System.out.println("q");
}
},
winter("冬",4){
@Override
public void show() {
System.out.println("d");
}
};
String name;
int id;
season(String name, int id) {
this.name = name;
this.id = id;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
}
注解
学完反射后再进行补充