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

The problem with the multiple bounds for the generic type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 7
    • 7
    • tools
    • None
    • generic
    • generic

      Javac allows to inherit a method with one signature from the superclass and a super interface at the same time.
      It is also not a problem if this method is protected in the class and is certainly public in the interface - you just have to override it as public in the subclass.

      But for some unclear reasons using the described class and the interface
      as the multiple bounds for a generic type doesn't work.

      Here it the minimal test case:

      class MyClass {
          protected void foo() {
          }
      }

      interface MyInterface {
          public void foo();
      }

      // MixedClass compiles fine
      class MixedClass extends MyClass implements MyInterface {
          public void foo() {
              super.foo();
          }
      }

      // this doesn't compile wit the message
      // foo() in MyClass cannot implement foo() in MyInterface
      // which isn't correct, because it perfectly can do it in the subclass
      public class GenericProblem<T extends MyClass & MyInterface> {

      }

      This problem is reproducible with the latest JDK 7

            Unassigned Unassigned
            alexp Alexander Potochkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: