JEP 359: Records

Brian Goetz brian.goetz at oracle.com
Fri Oct 11 18:23:29 UTC 2019


Well, what do you mean by "suitable"?  If a class has private fields, by 
what right would the compiler expose public accessors for them?  (And, 
if there already are public accessors, what would the benefit be of 
"treating them like records"?)

The purpose of having a new declaration form is so that the author can 
communicate their design intent.  WHen you say "record", you are making 
it crystal clear what you want -- that you intend that this class is a 
transparent, shallowly immutable carrier for a specified tuple of data.  
And, even if the compiler could figure out by analyzing the code that a 
given class conforms to the requirements for record _today_, that 
doesn't stop you from evolving the class in a different direction 
tomorrow (say, by adding mutable fields), and now you've got an 
incompatibility. Much better to let the programmer say what they mean.

On 10/11/2019 1:18 PM, Jonathan Rosenne wrote:
> May I suggest that the compiler detect suitable existing classes that could be records and treat them as such? For example the often used Point class, or the Integer class?
>
> Best Regards,
>
> Jonathan Rosenne
>



More information about the amber-dev mailing list