jdk5中出现的枚举不就已经将构造方法私有化了吗?,那张孝祥老师的“交通灯管理系统”中为什么还要手工私有化构造函数?这样不会冲突吗?附上部分代码,请大神帮我解答一下,万分感谢- public enum Lamp {
- S2N("N2S", "S2W", false), S2W("N2E", "E2W", false), E2W("N2E", "E2W", false), E2S(
- "W2N", "S2N", false), N2S(null, null, false), N2E(null, null, false), W2E(
- null, null, false), W2N(null, null, false), S2E(null, null, true), E2N(
- null, null, true), N2W(null, null, true), W2S(null, null, true);
- //私有化构造函数
- private Lamp() {
- }
- //私有化构造函数
- private Lamp(String opposite, String next, boolean lighted) {
- this.opposite = opposite;
- this.next = next;
- this.lighted = lighted;
- }
- ...
- }
复制代码
|
|