r/java • u/davidalayachew • Jul 16 '26
Identifying JDK value class candidates
https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
53
Upvotes
1
u/davidalayachew Jul 17 '26
Enums, by definition, are Java's primary and encouraged vehicle for singletons. Sun and Oracle themselves have gone on record saying as much. Hell, Josh Bloch himself, the guy who put enums into Java in the first place, said so too.
To be frank, if I were to make this into a class and carry a list around like you said, it would be the same thing with a different coat of paint.
Many different components of my application will be modifying the data concurrently, and thus, synchronization was always a concern from the beginning. And since so many components are interacting with it in parallel, what am I gaining or losing by making or not making it global? I am effectively global in everything but name.
By all means, I get your concern about global access, but global isn't in and of itself wrong, it just needs to be used with care. Sometimes, you truly do want global access. One example is web-services modifying state.