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

8.4.1: Error for receiver parameter of an inner class in a static context

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • 8, 9
    • specification

      Some inner classes can occur in static contexts (8.4.1)—e.g., a local class declared in a static method. But these inner classes have no immediately enclosing instance, so shouldn't have a receiver parameter.

      Proposed rule:

      A receiver parameter may appear only in the FormalParameterList of an instance method or ~~an inner class's constructor~~ **a constructor of an inner class, where the inner class is not declared in a static context**; otherwise, a compile-time error occurs.

      Or, if that's too much of a mouthful:

      A receiver parameter may appear only in the FormalParameterList of an instance method or an inner class's constructor; otherwise, a compile-time error occurs.

      **If a receiver parameter appears in the FormalParameterList of an inner class's constructor, but that class is declared in a static context, a compile-time error occurs.**

            abuckley Alex Buckley
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: