1

Here's the code snippet, coded and ran in Eclipse Kelper SR2 with the Java 8 support update installed (retrieved from here: click me):

public class InterfaceSwitchTest {

    public enum Enums {
        FOO,
        BAR;
    }

    public interface A {
        // The below method causes the error. 
        // Comment out or delete this method and this class will compile. 
        public default void switchStatement(final Enums x) {
            switch (x) {
                case FOO:
                    break;
                case BAR:
                    break;
            }
        }

        // The if statement version of the above.
        public default void ifStatement(final Enums x) {
            if (x.equals(Enums.FOO))
                return;
            if (x.equals(Enums.BAR))
                return;
        }
    }

    public static class AImplemented implements A {
        public AImplemented() {
        }
    }

    public static void main(final String[] args) {
        AImplemented instance = new AImplemented();
        System.out.print("Yay, no exeptions!");
    }
}

Executing the above without commenting out method "switchStatement()" will give the following exception during runtime:

Exception in thread "main" java.lang.ClassFormatError: Illegal field modifiers in class InterfaceSwitchTest$A: 0x100A

Is the above exception expected? The solution to the problem is, of course, to use the if-statement substitute. I'm just wondering why it causes the ClassFormatError?

If it is expected, I would very much like to hear an explanation.

Thanks!

NOTE: I've already setup my eclipse with the java 8 binaries. I have lambda expressions and other defender methods scattered throughout my project, and they run perfectly.

  • 1
    What happens when you compile it with javac? Nevermind, I just tested it with javac, and it compiles and runs fine. It must be an eclipse bug. – JB Nizet Apr 02 '14 at 21:37
  • @JBNizet Thanks for the input. The error wasn't there after compiling and running through command prompt. Perhaps it's just an eclipse issue. – user3491278 Apr 02 '14 at 21:54
  • i have the same error message. it still is an eclipse luna problem – Ray Tayek Mar 08 '15 at 05:04

0 Answers0