If you declared enum as follows:
enum Suit {SPADES, HEARTS, CLUBS, DIAMONDS}
The Java compiler will synthesize the following class for you:
final class Suit extends java.lang.Enum<Suit> { public static final Suit SPADES; public static final Suit HEARTS; public static final Suit CLUBS; public static final Suit DIAMONDS; private static final Suit[] $VALUES; public static Suit[] values(); public static Suit valueOf(java.lang.String); private Suit(); }
There is no intention to create other instances of this class that are different from those static fields that are already defined in it (as you could infer from its private constructor), but most importantly, and as mentioned in the accepted answer, the inner class cannot have static members ( JLS §8.1.3. Inner classes and Enclosing instances ), and since the synthetic enum class does, this makes it unacceptable as an inner class.
Edwin Dalorzo Oct 05 '17 at 21:29 2017-10-05 21:29
source share