今天尝试写了一个简单的了解了一下枚举类型,先附上代码吧:
//定了一个枚举类型Suit
public enum Suit {
CLUBS("black"),DIAMONDS("red"),HEARTS("red"),SPADES("black");
private final String color;
private Suit(String suitColor){
this.color = suitColor;
}
public String getColor(){
return color;
}
}
//接下来的是对这个枚举类的测试:
for(Suit nextSuit : Suit.values()){
System.out.println(nextSuit + " are [" + nextSuit.getClass() + "] and color is ["+nextSuit.getColor() +
"] and the ordinal value of "+ nextSuit.ordinal());
}