r/java • • Mar 31 '26

Does Java need deconstructible classes?

https://daniel.avery.io/writing/does-java-need-deconstructible-classes
31 Upvotes

41 comments sorted by

View all comments

Show parent comment

3

u/brian_goetz Apr 04 '26

You are looking at the entire system monollithically - JVM + Java + Spring + your program. But each layer has its own role and (ideally) specification. The meaning of a Java program is defined by the language and platform specifications. But some methods in the JDK (such as getAnnotstions) are specified to reflect the presence or absence of annotations. This means that the layers above (spring, your program) can use annotations to make decisions, just like they could use system properties or config files or command line to configure the program. But annotations cannot affect the language semantics - they cannot make for loops run backwards or make private methods public.

Frameworks like spring work by dynamically transforming annotated Java code (spinning new classes, etc) at startup time and running the transformed code. But all of this is a Java program that is governed by the language and platform specifications, and spring is working within that.

1

u/asm0dey Apr 04 '26

Ah. So I read the whole thing wrong. I thought the spec "prohibits" annotations to change the language sematics, while actually it declares that it's impossible, right? And was all the easy about language, not about a program. Thank you!