Updated document on data classes and sealed types

Alex Buckley alex.buckley at oracle.com
Sat Mar 2 01:05:06 UTC 2019


On 3/1/2019 12:14 PM, Brian Goetz wrote:
> While the previous version was mostly about tradeoffs, this version
> takes a much more opinionated interpretation of the feature, offering
> more examples of use cases of where it is intended to be used (and not
> used).

(Setting aside value records throughout.) A record type "codes like a 
class", not "codes like an int" -- you can `new` it, and the resulting 
record object has identity and can refer directly or indirectly to other 
record objects of the same type. (Contrast with LW1, "Value types may 
not declare fields of its own type directly or indirectly".) A variable 
of record type may even be null. The on-ramp to records looks smooth -- 
but can I compatibly turn a class type into a record type? It's 
potentially a source-compatible change (make the state description match 
the class's ctor), but binary-compatible?

Similarly, if a record type is chafing at the restrictions of "state 
only!", then can I (source|binary)-compatibly turn it into a class type?

Alex


More information about the amber-spec-experts mailing list