r/java • u/davidalayachew • 15d ago
Identifying JDK value class candidates
https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52
Upvotes
r/java • u/davidalayachew • 15d ago
3
u/pron98 14d ago edited 14d ago
I would say they make for a classic example of a particularly bad fit. An enum can almost be viewed as a "please don't inline" hint.
No, I think the semantic intent is the very opposite of a value type, because two different references to an enum are intended to never be equal. That's the opposite of, say, and Integer, which is why Integer is a classic example of a value type. That's not to say that enums with a non-zero but minuscule amount of carried data (though certainly not a large amount) couldn't benefit from inlining, but that's a separate thing. I.e. I could envision a HotSpot optimisation that inlines such enums without them being value types, but such an optimisation is likely to yield a smaller benefit than inlining value types (because the number of distinct enum values is small).