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

Receiver parameter not supported on local class constructor

    Details

    • Subcomponent:
    • Resolved In Build:
      b19
    • Verification:
      Verified

      Backports

        Description

        If an inner class is a member, then a receiver parameter works fine:

        class Top {
          class Inner {
            Inner(Top Top.this) {}
          }
        }

        but if the inner class is local:

        class Top {
          void m() {
            class Inner {
              Inner(Top Top.this) {}
            }
          }
        }

        then javac (JDK8 b116) gets confused - it thinks Inner is top level:

        error: receiver parameter not applicable for constructor of top-level class
              Inner(Top Top.this) {}
                        ^

        This is a bug. A local class is a perfectly good inner class - the ctor of Top$1Inner.class even takes a Top - so its constructor ought to permit a receiver parameter. This is even true when the local class is inside a default method of an interface - in that case, the type of the receiver parameter is the interface. (As of JLS8, it is legal to say InterfaceName.this inside a default method of an interface.)

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  pgovereau Paul Govereau (Inactive)
                  Reporter:
                  abuckley Alex Buckley
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  9 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: