References to static fields in enum initializers

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Consider this simple enumerated type:

class Foo {
foo, bar;

Foo() {
if( equals(foo) ) {
// ...
}
}
}

javac rightfully points out the illegal access to foo in the
initializer for the enumerated type. However, javac 1.6.0_01
cheerfully accepts

class Foo {
foo, bar;

Foo() {
switch(this) {
case foo:
break;
}
}
}

, which of course is broken and fails at runtime. My question: is
javac right to accept this code (meaning that the language definition
might need some work), or should I file a bug report?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top