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

javac should create bridge methods when type variable bounds restricted

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux, windows_xp

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: