Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8300786 Statements before super()
  3. JDK-8194743

Permit additional statements before this/super in constructors

    XMLWordPrintable

Details

    • Sub-task
    • Status: Open
    • P4
    • Resolution: Unresolved
    • None
    • tbd
    • specification
    • None

    Description

      Currently it is not permitted to precede the `this()` or `super()` call in a constructor invocation with statements. This often causes distorted control flow and challenges in refactoring.

      We would amend JLS 8.8.7 as follows:

      - Production is amended to:

          ConstructorBody:
              { [ BlockStatements ] [ ExplicitConstructorInvocation ] [ BlockStatements ] }
       
      - Restriction about first statement is relaxed to apply to the explicit ctor invocation, wherever it resides.

      - s/begin with/include/

      - Add note (somewhere) that in the first BlockStatement, `this` is DU, and in the second, `this` is DA.

      - Clarify that a return statement may only be used in the second BlockStatements.


      Attachments

        Issue Links

          Activity

            People

              acobbs Archie Cobbs
              briangoetz Brian Goetz
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated: