4 ms·
Sure, just as any immutable object is fine in this regard. But the point is not the fact that we can write some classes that are well-behaved in certain respect
by pron 4y ago
Sure, just as any immutable object is fine in this regard. But the point is not the fact that we can write some classes that are well-behaved in certain respects, but that we can reify a concept as construct known to provide those guarantees. That's exactly what enums and records do, but data classes don't.
You could always code regular classes with behaviour similar to that of enums or records, but the point of enums and records is that all enums and all records are known to have their respective kind of behaviour.