Hello @valhalla-dev <[email protected]>,

I was just watching the Inside Java Podcast, episode 68, and at 16:35 [1],
they start talking about operator overloading, mentioning at 17:53 [2] that
String can't be a value class.

I've heard bits and pieces of the why behind this claim, here and there,
something to do with hashCode. So, I looked at the source code for String
[3].

I see 2 mutable fields -- private int hash [4] and private boolean
hashIsZero [5]. But assuming that JEP 531: Lazy Constants (Third Preview)
[6] goes live, that should allow these 2 to be final fields.

I know there are other things required to be a value class, but I don't see
where String would fail those pre-requisites.

But let me first ask -- Is it true that String can't become a value class?
And if so, why not?

Thank you for your time.
David Alayachew

[1] = https://youtu.be/qGRAWfLLJFQ?si=vRZ_I_2BzRT0jh0D&t=995
[2] = https://youtu.be/qGRAWfLLJFQ?si=2PrN0Af_vys1Jtif&t=1073
[3] =
https://github.com/openjdk/jdk/blob/5962d86603a98a0f83aad6fcd6e9dcf90182504e/src/java.base/share/classes/java/lang/String.java
[4] =
https://github.com/openjdk/jdk/blob/5962d86603a98a0f83aad6fcd6e9dcf90182504e/src/java.base/share/classes/java/lang/String.java#L206
[5] =
https://github.com/openjdk/jdk/blob/5962d86603a98a0f83aad6fcd6e9dcf90182504e/src/java.base/share/classes/java/lang/String.java#L214
[6] = https://openjdk.org/jeps/531

Reply via email to