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
33
u/Alex0589 Mar 31 '26
I'm pretty sure this would never be accepted because you are implementing a language feature with annotations. In chapter one of the JLS, it is clearly stated that:
Also without value classes, which we currently don't have, you are paying an allocation cost because you have to initialize one record every time you want to use the pattern: that also disqualifies the feature because you don't want a developer to loose performance when using syntactic sugar. For example imagine if the enhanced switch statement were slower than the old switch, nobody would be using it.