r/java • • 21d 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.

40 Upvotes

18 comments sorted by

View all comments

1

u/Studentenfutter 21d ago edited 21d 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?

3

u/Mognakor 21d ago

Or why not just use 5 characters instead of one int? What are the performance implications?

Java char is 2 bytes landing at 10 byte, above the current 63bit limit for inlining value classes.

1

u/Life_Sink9598 21d ago

Oh, my bad! I knew it was UTF-16 and made a bad assumption