whi*_*win 1 java enums constants
我已阅读有关Java枚举的内容并定期使用它们.但是,我不明白为什么例如JFrame.EXIT_ON_CLOSE返回一个int.
考虑http://download.oracle.com/javase/1.5.0/docs/guide/language/enums.html ;
// int Enum Pattern - has severe problems!
public static final int SEASON_WINTER = 0;
public static final int SEASON_SPRING = 1;
public static final int SEASON_SUMMER = 2;
public static final int SEASON_FALL = 3;
Run Code Online (Sandbox Code Playgroud)
不是类型安全 - 因为一个季节只是一个int,你可以传递任何其他需要一个季节的int值,或者将两个季节加在一起(这没有任何意义).
JFrame.EXIT_ON_CLOSE返回3,同时JFrame.HIDE_ON_CLOSE返回1,这意味着后者中的三个等于第一个.
为什么这样实现?