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);
}
}