enum 枚举类型介绍

package enumpractice;

//运行下就差不多懂点了
public enum Color {
RED("红色",1),
GREEN("绿色",2),
NK("hhhhhh",1);
private String name;
private int index;
private Color(String name, int index) {
this.name = name;
this.index = index;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the index
*/
public int getIndex() {
return index;
}
/**
* @param index the index to set
*/
public void setIndex(int index) {
this.index = index;
}
public static String getName(int index){
for(Color c: Color.values()){
if(c.getIndex()==index){
System.out.println(c.getName());
//return c.name;
}
}
System.out.println(Color.GREEN.getName());

return "3123";

}

public static void main(String[] args) {
getName(1);
}


}

posted @ 2018-03-07 10:48  nkk  阅读(251)  评论(0编辑  收藏  举报