I just realized that an enum constant in Java seems containing all the enumeration constants of the same type.
For example, the following code is legitimate:
enum State {
enable, disable, deleted;
}
class Test {
public static void main(String[] args) {
for ( State s : State.enable.disable.values() ) {
System.out.println(s);
}
}
}
I was very surprised when I saw that the output is:
enable
disable
deleted
Isn't it counter-intuitive or even illogical that the enable
constant contains disable
constant which in turn constains all the State
enum constants?
What is the possible consideration behind this language design?