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

[local-methods] Javac should allow local methods above the chained constructor call this()/super()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: repo-amber
    • Fix Version/s: repo-amber
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Understanding:
      Fix Understood
    • CPU:
      generic
    • OS:
      generic

      Description

      Given:
      public class X {
        private static int get42() {
            return 42;
        }
         X() {
             this(get42());
         }
         X(int x) {
         }
      }

      The finder recommends that get42() can be local to X()

      If you move it in as a local method, it has to lose its private and static modifiers and the code would look like
      (the only modifiers accepted in a local method is final)

      public class X {
         X() {
             int get42() {
                 return 42;
             }
             this(get42());
         }
         X(int x) {
         }
      }

      This presently triggers: X.java:8: error: call to this must be first statement in constructor.

      Javac should allow local methods above this()/super() call, implicitly forcing them to be static.

        Attachments

          Activity

            People

            Assignee:
            sadayapalam Srikanth Adayapalam
            Reporter:
            sadayapalam Srikanth Adayapalam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: