Why don't java enums allow accessing item-specific fields/methods

Viewed 66

You are allowed to have enum fields/methods that are specific to each item like this in java

enum E {
    A {
        public int a = 3;
    },
    B {
        public void x() {}
    };
}

But you are not allowed to do this:

int x = E.A.a; // cannot resolve symbol 'a'
E.B.x() // cannot resolve method 'x'

Why is this not allowed?

0 Answers
Related