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

Generics problem with interface implementation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 5.0
    • tools
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      "1.5.0" build 1.5.0-b64

      ADDITIONAL OS VERSION INFORMATION :
      WindowsXP sp2

      A DESCRIPTION OF THE PROBLEM :
      The following code generates a compilation problem on the last line of class X: String s = secondInterface.find(new Integer(1));
      SecondInterface has clearly specified String & Integer when it extends FirstInterface, and one should be able to invoke a method against a variable defined as a SecondInterface when the method is from the FirstInterface.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code that is supplied

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No compilation problem
      ACTUAL -
      Compilation error on the last statement in class X...

      incompatible types
      found : java.lang.Object
      requried: java.lang.String

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Compilation error on the last statement in class X...

      incompatible types
      found : java.lang.Object
      requried: java.lang.String

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      interface FirstInterface <O,N> {
          public O find(N number);
      }

      interface SecondInterface <T extends CharSequence> extends FirstInterface<String, Integer> {
          public String convert(T charSequence);
      }


      class SecondClass implements SecondInterface<StringBuilder> {
          public String find(Integer i) { return null; }
          public String convert(StringBuilder stringBuilder) { return null; }
      }

      class X {
          public static void main(String[] args) {
              SecondInterface secondInterface = new SecondClass();
              secondInterface.find(new Integer(1));
              String s = secondInterface.find(new Integer(1));
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: