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

Malte Skoruppa mskoruppa at ripstech.com
Thu Mar 29 14:15:53 UTC 2018


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,

-- 
*Dr. Malte Skoruppa*
*Lead Software Engineer*
mskoruppa at ripstech.com <mailto:nfritsch at ripstech.com>

*RIPS TECHNOLOGIES GMBH*
Universitaetsstrasse 142
44799 Bochum
Germany

www.ripstech.com <https://www.ripstech.com>
<https://www.ripstech.com>
<https://www.ripstech.com><https://www.facebook.com/ripstech>
<https://twitter.com/ripstech>
<https://www.linkedin.com/company/rips-technologies>
<https://www.youtube.com/channel/UCcyddj_Aw1QAMpNZrtmZUHg>
<https://github.com/rips>
RIPS Technologies GmbH


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