If I declare a variable before or without declaring enum constants in this way:
enum MyEnum
{
int i = 90;
}
It shows following compilation error.
MyEnum.java:3: <identifier> expected
{
^
MyEnum.java:4: ',', '}', or ';' expected
int i = 90;
^
MyEnum.java:4: '}' expected
int i = 90;
^
MyEnum.java:5: class, interface, or enum expected
}
^
4 errors
But if I declare an enum constant before declaring i
then it compiles fine.
Even the following code will compile fine:
enum MyEnum
{
;//put a semicolon
int i = 90;
}
Why java enum is designed in this way?