Clarifying the receiver parameter (qualified 'this')

Alex Buckley alex.buckley at oracle.com
Wed Oct 23 11:27:25 PDT 2013


On 10/23/2013 3:47 AM, Markus Keller wrote:
> In reply to Michael Ernst <mernst at cs.washington.edu>'s
> http://mail.openjdk.java.net/pipermail/type-annotations-spec-experts/2013-October/000159.html
>
> Yes, we're not at all questioning the "Outer.this" notation for inner
> class constructors.
>
> I just find it awkward that the 308.pdf replaced
> java-annotation-design.html's
>      [Identifier .] this
> with
>      {Identifier .} this
> and allows (fully-)qualified 'this' expressions as the name of the
> receiver parameter even where that's not necessary.
>
> The argument about analogy to qualified 'this' expressions in a method
> body is IMO too far-fetched, since the receiver parameter is closer to
> being a declaration rather than a reference.

The receiver parameter is _not_ "closer to being a declaration", as 
308.pdf makes clear: "It is not a formal parameter. More precisely, it 
is not a declaration of any kind of variable (4.12.3), is never bound to 
any value passed as an argument in a method invocation expression, and 
has no effect whatsoever at run time."

As Mike pointed out, there is a pleasing consistency between the name of 
the receiver parameter and the name in a qualified this expression in 
the ctor body - both reflect the type of the immediately enclosing 
instance which may in general be qualified, e.g. pkg1.pkg2.Outer.

> By the same argument, you
> would also have to allow other names in declarations to be redundantly
> qualified, e.g.:
>
>      package my.pack;
>      public class my.pack.Example { // illegal (good)
>          my.pack.Example() { }  // illegal (good)
>          void my.pack.Example.foo() { } // illegal (good)
>          void bar(@Const Example my.pack.Example.this) { } // should be
> illegal
>      }

The premise of the above paragraph - that the receiver parameter is a 
declaration made with a qualified name - is false so the example is 
ill-conceived. A declaration of a class, a constructor, a method, a 
formal parameter uses a simple name by definition.

Alex


More information about the type-annotations-spec-experts mailing list