Parenthesized "this" and final fields
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Jun 7 20:54:38 UTC 2018
>
> Still, right now, JLS10 says that Tagir's first example, with
> parentheses removed, should compile, but he says it doesn't:
>
> class Unassigned {
> final int x = this.y + 1;
> final int y = this.x + 1;
> }
I tested it and this compiles correctly. I don't know what specific
example Tagir was referring to.
>
>> As for the second example, I think the point of contention is all around
>> this sentence in the spec:
>>
>> > Throughout the rest of this chapter, we will, unless explicitly
>> stated otherwise, write V to represent a local variable or blank |final|
>> field which is in scope (§6.3
>> <https://docs.oracle.com/javase/specs/jls/se10/html/jls-6.html#jls-6.3>).
>> Likewise,
>> we will use |a|, |b|, |c|, and |e| to represent expressions, and S and T
>> to represent statements. We will use the phrase "|a| is V" to mean that
>> |a| is either the simple name of the variable V, or V's simple name
>> qualified by |this| (ignoring parentheses). We will use the phrase "|a|
>> is not V" to mean the negation of "|a| is V".
>>
>> What does this mean? I see many different ways to add parenthesis to a
>> qualified this reference:
>>
>> (this).x = value //as in your example
>> (this.x) = value
>>
>> I trust that the spec here means that every parenthesis should be
>> dropped; which would suggest we have a bug here.
>
> Right. The "ignoring parentheses" clause ought to appear in 16.0 too.
I mean, I think the spec is fine here, but javac only deals with the
second kind of parenthesis, not the former - should javac be changed to
drop both kind of parenthesis?
Maurizio
>
> Alex
More information about the compiler-dev
mailing list