Java: Local Enums

Posted by bruno conde on Stack Overflow See other posts from Stack Overflow or by bruno conde
Published on 2009-03-31T13:02:28Z Indexed on 2010/05/26 5:31 UTC
Read the original article Hit count: 353

Filed under:
|

Today, I found myself coding something like this ...

public class LocalEnums {

    public LocalEnums() {
    }

    public void foo() {
    	enum LocalEnum {
    		A,B,C
    	};

    	// ....
    	// class LocalClass { }

    }
}

and I was kind of surprised when the compiler reported an error on the local enum:

The member enum LocalEnum cannot be local

Why can't enums be declared local like classes?

I found this very useful in certain situations. In the case I was working, the rest of the code didn't need to know anything about the enum.

Is there any structural/design conflict that explains why this is not possible or could this be a future feature of Java?

© Stack Overflow or respective owner

Related posts about java

Related posts about enums