Draft JLS spec for records

Stephan Herrmann stephan.herrmann at berlin.de
Sat Sep 7 12:21:57 UTC 2019

Maybe you've been waiting for this question from me :)

 > The restricted identifiers var and record are not keywords.
 > var has special meaning as the type of a local variable declaration
 > (14.4, 14.14.1, 14.14.2, 14.20.3) and the type of a lambda formal
 > parameter (15.27.1). record has a special meaning in a record type
 > declaration (8.10).

What exactly is the meaning of "restricted identifier"?

With 'var' I thought it to be this:

The parser may safely classify it as an Identifier, the following two are 
equivalent during parsing:
    Foo var;
    var var;
Only later during semantic analysis we need to detect that the occurrence of 
'var' in type position does not refer to any declared type but should be 
inferred. Nice.

Can this possibly work for 'record'? Let's try:
    public Foo    MyRecord (String f1) { String m() { return f1; } }
    public record MyRecord (String f1) { String m() { return f1; } }
If the second word in each declaration is an Identifier, then the parser will 
see the start of a method declaration, but then things go wrong left (set of 
legal modifiers) and right (set of legal body declarations).

IMO, this puts 'record' rather into the bucket of restricted keywords, because 
the correct classification as identifier or keyword is necessary already during 

Please prove me wrong. It would be very nice if 'record' was as little 
disruptive as 'var' was, but I don't see this.

After reclassifying 'record' to "restricted keyword", the restriction against 
'record' as a type name can even be lifted, so the following are equally valid:
   module module {}
   record record(String f) {}


More information about the amber-spec-observers mailing list