[359] Record - Compact Constructor should not have throws clause
Tagir Valeev
amaembo at gmail.com
Tue Feb 11 03:23:22 UTC 2020
Hello!
вт, 11 февр. 2020 г., 10:18 Manoj Palat <manoj.palat at in.ibm.com>:
> Hi,
>
> consider
> record R(){
> public R throws Exception {}
> }
>
> From JLS 14 Sec 8.10.4,
> A canonical constructor must not have a throws clause.
>
> Sec 8.10.5 says
> A compact constructor is a canonical constructor.
>
> By the above two, it can be inferred that a compact constructor must not have a throws clause. However, there is no explicit mention of this restriction in Sec 8.10.5 [1]
>
> I think it would good to add this explicitly in the next version of spec (assuming the above is true).
>
>
This unambiguously follows from the compact constructor declaration
production:
*CompactConstructorDeclaration*:{ *Annotation* } { *ConstructorModifier* }
*SimpleTypeName* *ConstructorBody*
No throws at all here. To me, this is enough and no changes are necessary.
With best regards,
Tagir Valeev.
[1] http://cr.openjdk.java.net/~gbierman/jep359/jep359-20200115/specs/records-jls.html#jls-8.10.5
> Regards,
> Manoj.
>
> Side Note:
> To compare, javac throws errors but not this particular error (may be due to error recovery)
> javac14 --enable-preview --release 14 X.java
> X.java:2: error: <identifier> expected
> public R throws Exception {}
> ^
> X.java:2: error: field declaration must be static
> public R throws Exception {}
> ^
> (consider replacing field with record component)
> X.java:2: error: invalid method declaration; return type required
> public R throws Exception {}
>
>
>
>
More information about the amber-spec-observers
mailing list