RFR: 8204610: Compiler confused by parenthesized "this" in final fields assignments

Alex Buckley alex.buckley at oracle.com
Tue Jun 12 18:05:30 UTC 2018


On 6/11/2018 7:41 PM, Liam Miller-Cushon wrote:
> On Mon, Jun 11, 2018 at 2:35 PM Alex Buckley <alex.buckley at oracle.com
> <mailto:alex.buckley at oracle.com>> wrote:
>
>     All that said, if you can count the qualified-`this` names used in your
>     codebase to (i, RHS) access a variable's value, and (ii, LHS) denote the
>     variable to assign to, then it would be interesting info.
>
> I found about 3200 occurrences of (i) and 7100 occurrences of (ii).
>
> That's not a large absolute number. (As expected, it's a small fraction
> of unqualified this accesses.)

Sorry, I should have been clearer. Let's set assignment aside. I wanted 
to ask how many times `TYPENAME.this.x` is used to access the value of a 
blank final field in an enclosing class.

However, my question is ill-formed. As below, a blank final field (x) in 
an enclosing class (A) must be assigned by the end of construction of 
that class; if it isn't, and the compiler gives an error, then it's moot 
whether an enclosed class (B) refers to the blank final field via 
`A.this.x`.

public class Top {
   class A {
     final int x;

     class B {
       int y = A.this.x + 1;
     }
   }

   public static void main(String[] a) {
     Top.A.B b = new Top().new A().new B();
   }
}

Let's set aside blank final fields, and return to ordinary forward field 
references. How many times is `this.x` or `TYPENAME.this.x` used to 
forward-reference a field where using simple `x` would raise an error?

Alex


More information about the compiler-dev mailing list