----- Original Message ----- > From: "daniel smith" <[email protected]> > To: "John Bossons" <[email protected]> > Cc: "valhalla-dev" <[email protected]> > Sent: Wednesday, September 2, 2026 7:41:15 PM > Subject: Re: [External] : Is it true that String can't become a value class? > And if so, why not?
>> On Sep 2, 2026, at 7:40 AM, John Bossons <[email protected]> wrote: >> >> Sorry, I should have made it clear that I was referring to fixed-length >> small strings, such as country-specific postal codes. > > If you want to minimize the memory footprint of a fixed-length alphanumeric > code, here’s a tool you can use today: > > value class Alphanum6 implements Comparable<Alphanum6> { > private int bits; > public Alphanum6(String code) { > if (code.length() != 6) throw new IllegalArgumentException(); > bits = Integer.parseUnsignedInt(code, 36); > } > public String code() { return Integer.toUnsignedString(bits, > 36).toUpperCase(Locale.ROOT); // <--- > } > public String toString() { return code(); } > public int compareTo(Alphanum6 that) { return > Integer.compareUnsigned(this.bits, > that.bits); } > } fixing a small bug, you do not want toUpperCase() to be Locale sensitive. regards, Rémi
