Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7049773

Inconsistent compilation results for enum implementing an interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u25
    • tools
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_25"
      Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
      Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Assuming we have the following 3 classes:

      1. EnumInterface .java:

      public interface EnumInterface {

      public void doSomething();
      }

      2. EnumImplements .java
      public enum EnumImplements implements EnumInterface {
      A1 {
      @Override
      public void doSomething() {
      }
      };
      }

      3. Main.java
      public class Main {
      public static void main(String[] args) {
      EnumImplements ei = EnumImplements.A1;
      ei.doSomething();
      }
      }

      Now, if we compile Main.java, we get::
      Main.java:6: cannot find symbol
      symbol : method doSomething()
      location: class EnumImplements
                      ei.doSomething();
                        ^
      1 error

      But if we compile EnumImplements.java first, and than Main.java (I.e. 2 javac commands), the compilation succeeds.

      The workaround we found was to declare the interface method as abstract in EnumImplements.java:
      public enum EnumImplements implements EnumInterface {
      A1 {
      @Override
      public void doSomething() {
      }
      };
              public abstract void doSomething();
      }




      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: