Java灵活使用枚举表示一组字符串

public class HelloWorld {
    public static void main(String []args) {
       System.out.println("Hello World!");
		System.out.println(Season.SPRING.toString());
		System.out.println(Season.SPRING.value());
    }
}

enum Season {
	SPRING("spring"), SUMMER("summer"), AUTUMN("autumn"), WINTER("winter");
	
	public final String value;
	private Season(String value) {
		this.value = value;
	}
	
	public String value() {
		return this.value;
	}
}

程序输出结果如下:

Hello World!
SPRING
spring

你可能感兴趣的:(Java,编程思想)