<i18n dev> RFR: 8287860: Revise usage of volatile in j.u.Locale

liach duke at openjdk.java.net
Mon Jun 6 13:36:54 UTC 2022


On Mon, 6 Jun 2022 13:32:21 GMT, liach <duke at openjdk.java.net> wrote:

>> Shouldn't the fields annotated with `@Stable` be `final` as well?
>
> These fields can only be written once besides the default values, but they don't have to be written in the static initializer or constructor. So when a non-zero hash code is written, it's cached as if it's a final field. For a zero value, it would always undergo extra calculations like before and write multiple times, but the writes don't matter as it would only write zero, which would not yield false hash code if a previously written 0 value is cached.

> Shouldn't the fields annotated with `@Stable` be `final` as well?

You might have seen `@Stable final` fields. Those are only meaningful for arrays, where such caching happens at each array index. For non-arrays, `@Stable final` is simply equivalent to `final`, and simple `@Stable` acts as what I said above.

-------------

PR: https://git.openjdk.java.net/jdk/pull/9041


More information about the i18n-dev mailing list