考虑这样的枚举:
public enum SomeEnum {
REACT_TO_EVERYTHING,
REACT_TO_MOST {
@Override
public void method1() {}
}, REACT_TO_SOME {
@Override
public void method1() {}
@Override
public void method2() {}
}, REACT_TO_NOTHING {
@Override
public void method1() {}
@Override
public void method2() {}
@Override
public void method3() {}
};
public void method1() {
System.out.println("Hello");
}
public void method2() {
System.out.println("Stack");
}
public void method3() {
System.out.println("Overflow");
}
}
当REACT_TO_SOME
延长REACT_TO_MOST
时,以及REACT_TO_NOTHING
延长REACT_TO_SOME
时,此实施会更加干燥。
Java是否允许这样做?