Mistake in JLS 8.4.1 (Java SE 8 / 9 /10)

Alex Buckley alex.buckley at oracle.com
Wed Apr 4 22:21:39 UTC 2018


You make a fair point. We'll clarify this statement (or maybe even drop 
it) as part of reworking 8.4.1 for JEP 323 (var in lambda formals).

Alex

On 3/29/2018 7:15 AM, Malte Skoruppa wrote:
> Dear JLS Team,
>
> I found what I believe to be a small mistake in section 8.4.1 of the JLS
> for Java SE 8, 9, and 10.
>
> In this section it is stated:
>
>> If a method or constructor has no formal parameters, only an empty
>> pair of parentheses appears in the declaration of the method or
>> constructor.
>>
> I believe this statement to be incorrect for the following reason:
>
> If a method or constructor that has no formal parameters uses a receiver
> parameter in its declaration, then no empty pair of parentheses appears
> in the declaration, even though the method or constructor has no formal
> parameters. This directly contradicts the above statement.
>
> For example, the method:
>
> class A {
>
>    foo(A this) { ... }
>
> }
>
> has no formal parameters, yet no empty pair of parentheses appears in
> its declaration.
>
> I can tell from personal experience that the statement is indeed
> confusing: When I read it at first, I implicitly inferred from it that a
> receiver parameter must also be (a special kind of) formal parameter
> (since otherwise the statement would be incorrect). However, this is not
> true. Later in the same section (8.4.1), it is explicitly stated that:
>
>> The receiver parameter is not a formal parameter
>
> Therefore I propose to rephrase the statement as follows:
>
>> If a method or constructor has no formal parameters *and does not
>> specify a receiver parameter*, only an empty pair of parentheses
>> appears in the declaration of the method or constructor.
>>
> ...or similar.
>
> Best,
>


More information about the jls-jvms-spec-comments mailing list