asian new zealand IT

Java enum defies the law of physics?

, posted: 1-Mar-2007 12:13

Seems like Java's new keyword 'enum' is a real special one. I could compiled this source code with no problem:

class DayContainer {
// private inner class that shouldn't be accessible to outside DayContainer class.
private enum DayEnum {

public class TestEnum {

public static void main(String[] args) {
// Wow, DayEnum is still accessible!

public static void dayEnumString(DayEnum day) {
switch(day) {
case SUNDAY:
System.out.println("it's Sunday");

So, even though DayEnum is declared as a private inner class of class DayContainer, class TestEnum can happily access DayEnum as if it is an independent public class.


My fault, I didn't delete the class file before recompiling, hence the compile picked up the old class file. Hmm, got to watch out on old classes!

Other related posts:
Food delivery Auckland
php phd
Pizza King (Wellington)

Comment by nairda, on 1-Mar-2007 14:38

I cannot understand why it would compile.  Your sample source code wouldn't compile for me.

Author's note by asianbro, on 1-Mar-2007 14:47

Check your java version.

Mine is:

C:\>javac -version
javac 1.5.0_07

Author's note by asianbro, on 1-Mar-2007 14:53

Upps, my fault, seems like I should have deleted the DayEnum.class first! Sorry

Add a comment

Please note: comments that are inappropriate or promotional in nature will be deleted. E-mail addresses are not displayed, but you must enter a valid e-mail address to confirm your comments.

Are you a registered Geekzone user? Login to have the fields below automatically filled in for you and to enable links in comments. If you have (or qualify to have) a Geekzone Blog then your comment will be automatically confirmed and shown in this blog post.

Your name:

Your e-mail:

Your webpage: