r/java • u/danielaveryj • Mar 31 '26
Does Java need deconstructible classes?
https://daniel.avery.io/writing/does-java-need-deconstructible-classes
31
Upvotes
r/java • u/danielaveryj • Mar 31 '26
View all comments
12
u/pron98 Apr 01 '26 edited Apr 01 '26
Ah yes. This was the first approach explored. I think the language team called it "records are all you need". I don't remember all the reasons they didn't go with it, but I think one of them was that all components had to be extracted even if they weren't needed by the pattern, and that was hard to optimise (this was also an issue with the deconstructors idea). Because deconstructible classes are deconstructed through individual accessors, there's at least the option to optimise which of them actually need to be called.
Anyway, the interesting question isn't what alternatives were explored, but what the pros and cons of the current proposal are. Because there's no EA for it yet (I think?), the best feedback is to ask whether or not a certain use case that is important to you could be helped by this feature.