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

No support for automatic delegation...

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 6
    • tools
    • sparc
    • solaris_10

      A DESCRIPTION OF THE REQUEST :
      I propose a new annotation to handle the delegation required to do the same functionality multiple inheritance supports.

      JUSTIFICATION :
      Normaly developers are forced to delegate manualy to external objects, when implementing new interfaces. This process is error prone, as often more then one interface has the same method (IE: Account, and Person may both have a getID() method), this can lead to confusion.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The proposed "delegate" annotation would delegate ALL calls for a given interface to an instance of said interface in the object...
      IE:
      given...
      interface Person {
          public String getNameOfPerson();
      }
      and...
      class FancyBigPerson {
          @delegate Person
          private BigPerson getPersion() { return...; }
      }

      Will be identical to...
      class FancyBigPerson implements Person {
          private BigPerson getPersion() { return...; }
          public String getNameOfPerson() {
              return getPerson().getNameOfPerson();
          }
      }

      Any conflicts between interface should generate a compile time error, though the class should be allowed to overide (assuming properly annotated) the methods.
      ACTUAL -
      No support for anything like this.

      ---------- BEGIN SOURCE ----------
      import junit.framework.TestCase;

      public class DelegateTest extends TestCase {
      private static final String STRING = "String";
      public void testDelegate() {
      Root obj = new Root();
      assertEquals(
      "Did not delagate to target",
      STRING,
      obj.getTargetString()
      );
      }
      private interface Target {
      public String getTargetString();
      }
      public class Root {
      @Delegate( Target.class )
      public Target getTarget() {
      return new Target() {
      public String getTargetString() {
      return STRING;
      }
      };
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Manual, bug prone hard codeing of every item, of every interface.

            ahe Peter Ahe
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: