3 ms·
It's sad they introduced two kind of classes: "value" and these "kinds" together with both classes and records, java becomes much more complicated IMO.
by boroboro4 5y ago
It's sad they introduced two kind of classes: "value" and these "kinds" together with both classes and records, java becomes much more complicated IMO.
- kaba0 5y agoI think these are different semantic axes. There is one axis of less and less safety guarantees (identity, value, primitive) while records are more of a “here is a short syntax if you promise to keep some conventions”. But as mentioned in probably the second part, `value record` will also work properly.
- boroboro4 5y agoWhile what you're saying true I'm pretty sure it's going to create a lot of confusion - these things share a lot - all of them have all the fields final for example, and feel like "simple" "data" classes. I can see their reasoning to add value classes in addition to primitive classes, but the difference between them is going to create the most confusion, since they are identical in terms of requirements to classes themselves.
- kaba0 5y agoIt will definitely give some additional learning to people, but I feel like their usage is still quite idiomatic. If someone didn’t even hear about these, he/she can still code as if they are identity-based classes for the most time (chances are they are not the one writing vanilla concurrent code with synchronized or using some advanced optimizations with identityHashCode), and conversely spamming value and primitive may fail at compile time or at worse, runtime with some meaningful error.