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

javac should create bridge methods when type variable bounds restricted

XMLWordPrintable

    • x86
    • linux, windows_xp

      A DESCRIPTION OF THE REQUEST :
      When a subtype restricts the bounds of a type variable of its supertype, any inherited methods with a return type of that variable should have a bridge method created. Currently, moving such a method from the derived to base type will cause binary incompatibility.

      Care needs to be exercised for protected methods inherited across packages.

      JUSTIFICATION :
      It should be possible to move such methods to super types, without binary incompatibility.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      $ /usr/java/jdk1.6.0/bin/javap Derived
      Compiled from "Derived.java"
      public class Derived extends Base{
          public Derived();
          Derived getThis();
          Base getThis();
          public Derived function();
      }
      ACTUAL -
      $ /usr/java/jdk1.6.0/bin/javap Derived
      Compiled from "Derived.java"
      public class Derived extends Base{
          public Derived();
          Derived getThis();
          Base getThis();
      }

      with 1.5.0_04:

      C:\>javac Derived.java

      C:\>javap Derived
      Compiled from "Derived.java"
      public class Derived extends Base{
          public Derived();
          Derived getThis();
          Base getThis();
      }


      ---------- BEGIN SOURCE ----------
      abstract class Base<THIS extends Base> {
          abstract THIS getThis();
          public THIS function() {
               return getThis();
          }
      }
      public class Derived extends Base<Derived> {
          Derived getThis() {
              return this;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Override all methods with this problem.

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: