package enumtest;
public class Cut {
public static void main(String[] args) {
Color color1 = Color.ORANGE;
switch (color1){
case RED:
System.out.println("匹配到红色");
color1.show();
break;
case BLUE:
Color color2 = Color.BLUE;
color2.show();
System.out.println("匹配到蓝色");
break;
case GREEN:
Color color3 = Color.GREEN;
color3.show();
System.out.println("匹配到绿色");
break;
default:
System.out.println("颜色匹配错误");
}
}
}
enum Color implements H{
RED(255,0,0),BLUE(0,0,255),
GREEN(0,255,0), ORANGE(0,0,0);
private int redValue;
private int blueValue;
private int greenValue;
Color(int redValue, int blueValue, int greenValue) {
this.redValue = redValue;
this.blueValue = blueValue;
this.greenValue = greenValue;
}
@Override
public void show() {
System.out.println(redValue+","+blueValue+","+greenValue);
}
@Override
public String toString() {
return "Color{" +
"redValue=" + redValue +
", blueValue=" + blueValue +
", greenValue=" + greenValue +
'}';
}
}
interface H{
public void show();
}
|