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

Relax constraint on placement of super() call in constructors

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.4, 1.1.5, 1.4.1, 1.4.2, 5.0, 7
    • specification
    • x86, sparc
    • solaris_2.5.1, windows_nt, windows_xp, windows_7

      Name: rm29839 Date: 11/19/97


      The restriction that a call to a superclass constructor can only be placed as the first statement of a constructor serves
       no purpose and should be relaxed; i.e., it should be possible to invoke a superclass constructor anywhere in a constructor,
      as long as it's guaranteed that exactly one such call is executed. I believe this could be verified using the same flow analysis t
      hat is already applied to verify the initialization of blank finals. Obviously, references to instance variables or instance
      methods would be disallowed until after the superclass constructor has returned.

      The current constraint distorts the implementation of some classes by encouraging programmers to place complex
      expressions into the argument list of a call to super(). Here's a not-atypical local example:

      super(c,HashtableUtil.
               makeHashtable(
                     new Object[] {"jobNumber","fundId","detailedFundId"},
                     new Object[] {job.jobNumber(),
                                       detailedFund.fund().id(),
                                       detailedFund.id()}));

      The above also applies to calls to forms of this(), of course.
      (Review ID: 20079)
      ======================================================================

            abuckley Alex Buckley
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: