JAvaでの列挙タイプEnum

727 ワード

JAvaでの列挙タイプEnum
 TestEnum.java
/*
	    Enum
*/
public class TestEnum {
	//      MyColor,MyDoorOpener,    
	public enum MyColor { red, green, blue };
	public enum MyDoorOpener {me, mywife};
	
	public static void main(String[] args) {
		//      MyColor  red,MyColor.red          
		//   MyColor   ,        
		MyColor m = MyColor.red;
		//  m  
		switch(m) {
			case red:
				System.out.println("red");
				break;
			case green:
				System.out.println("green");
				break;
			default:
				System.out.println("default");
		}
		System.out.println(m);
	}
}

 
F:\java>javac TestEnum.java

F:\java>java TestEnum
red
red

F:\java>