Generics bug with Enum<?> instanceof

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 6
    • Component/s: tools
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Server VM (build 1.6.0-b105, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux XXX 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      The code snippet given below does not compile

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the given code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should compile
      ACTUAL -
      It does not

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      X.java:5: inconvertible types
      found : java.lang.Enum<capture#262 of ?>
      required: E
            if (o instanceof E) {
                ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      enum E { }

      class X {
          void f(Enum<?> o) {
            if (o instanceof E) {
              return;
            }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use E.class.isInstance(o)

            Assignee:
            Maurizio Cimadamore
            Reporter:
            Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: