Community
Participate
Working Groups
Build 20041201: The following legal J2SE5 program public class Test { public static void main(String[] args) { enum Count {} } } compiles with the following error Syntax error on token "enum", interface expected There are 2 problems: (1) the error message is misleading - "interface" is definitely *never* expected in a block (2) local enum declarations appear to be legal. According to the grammar rules in JLS3 14.2, BlockStatement: LocalVariableDeclarationStatement ClassDeclaration Statement and in 8.1, ClassDeclaration: NormalClassDeclaration EnumDeclaration I can't see any mention in the spec that they are illegal. java_1_5.g is not currently handling this case.
Jim, javac reports: X.java:3: enum types must not be local enum Count {} ^ 1 error
Page 255, look at the discussion topic. "This implies that it is impossible to define a local enum , or to define an enum for an inner class. So I would keep it as is for now.
David, Please add the same support than for invalid local interfaces. The code is illegal, so this is not a priority, but adding the same support could allow us to improve the error message.
*** This bug has been marked as a duplicate of 87818 ***