JDK-6542046 : Method-scoped enums no longer allowed
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0u12
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-04-03
  • Updated: 2010-04-26
  • Resolved: 2007-06-08
Related Reports
Relates :  
Description
a compiler error "enum types must be local", check a similar discussion going on at
http://forum.java.sun.com/thread.jspa?forumID=54&threadID=595962

It seems that prior to Java 1.5.0_01 method-scoped enums were allowed:

static void main(String[] args)
{
  enum Colors { RED, GREEN, BLUE };
}

but once in 1.5.0_01 you get the aforementioned compiler error. sounds like
a regression in bug #5081785?

Comments
EVALUATION As noted in JLSv3 section 8.5, "[Since nested enums are implicitly static] This implies that it is impossible to define a local enum, or to define an enum in an inner class." As of 1.5.0_01, javac correctly rejects invalid programs that define enums inside methods (local enums). Closing as not a bug.
08-06-2007