3 ms·
I'm saying that records are a semantic features, while data classes are not. In the context of records, "the extra flexibility of adding mutable state" makes a
by pron 4y ago
I'm saying that records are a semantic features, while data classes are not.
In the context of records, "the extra flexibility of adding mutable state" makes as much sense as saying that sometimes I like the flexibility of adding new instances to my enum classes on the fly. An enum is an enum to guarantee a fixed set of instances in the type.
That records and enums are more constrained in their behaviour than ordinary classes is the reason for their existence, because they don't do anything an object of a regular class can't do. Data classes, on the other hand, exist for syntactic brevity. The difference between the features is not a difference in degree but a difference in kind.