[records] Confusing compilation error when record components are omitted

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Dec 5 08:26:56 UTC 2019


You are right - this is confusing. That said, javac is not super-smart 
in this department, here's another (not records-related):

Test.java:4: error: ';' expected
     public String foo { return "foo"; }
                      ^
1 error

But the one you found is particularly disturbing - I agree

Maurizio

On 05/12/2019 07:26, Tagir Valeev wrote:
> Hello!
>
> My colleague experiments with records support. He made a fresh build
> from amber records branch and wrote this code:
>
> public record Record {
> }
>
> Compiler produced the following error message:
>
> error: class, interface, enum, or record expected
> public record Record {
>         ^
> 1 error
>
> It's pretty confusing to see the compiler pointing on the word
> 'record' and saying that 'record' is expected. The real problem is the
> absence of parentheses after the record name. I think such kind of
> mistake could be done by many newcomers. Probably a better compilation
> error should be displayed in this case?
>
> With best regards,
> Tagir Valeev.


More information about the amber-dev mailing list