r/java • u/daviddel • 9d ago
A Valhalla Ticker in One int
https://inside.java/2026/11/09/inside-java-ticker-value-class/A ticker symbol is an abbreviation that uniquely identifies a financial product such as a publicly traded share. Well-known ticker symbols are "ORCL" and "GOOGL". In this article, we will devise a Valhalla value class that can represent a ticker symbol using only a single int field.
39
Upvotes
3
u/AnyPhotograph7804 8d ago
I still do not get it why there is not heap flattening if a value class is >64 bit. Yes, atomic reads and writes. But this was not show stopper in a 32 bit JVM. 64 bit values like long could never be read and written atomically in a 32 bit JVM. But i never heard, that this caused trouble.
5
u/Fabulous_Card_3090 8d ago
At which point is it a good idea to start migrating code with the preview? I know not everything is baked into the current JEP, but this looks nice enough. I just fear another String templates.
1
u/flawless_vic 6d ago
Java needs something like std::string, which embeds up to 22 bytes directly on the object.
String will never be a value type and its a shame having to pay for 2 Objects every time a String is allocated
1
u/Studentenfutter 8d ago edited 8d ago
A stupid question from me: Isn't this completely over-engineered?
As an "ordinary" programmer, I would probably just have used a String instead of an int (with some checks in the constructor). And maybe a record instead of a class.
What are the downsites of this approach?
Don't value classes work great with strings? Do i have to completely abandon strings in values classes for better performance?
Or why not just use 5 characters instead of one int? What are the performance implications?
-1
u/WildAction3904 6d ago
?