StableValue and non-deterministic iteration order

Pavel Rappo pavel.rappo at gmail.com
Fri Sep 5 20:31:41 UTC 2025


We should be careful with words here. I think that in this thread
people use "deterministic" casually as a synonym for "defined".
"Defined" means not only repeatable but also specific. What's more,
people seem to want to be able to specify it. So, arguably a better
way would be to refer to such an order as **user-defined**.

Back to Map.of. Even if a user could control the seed of the current
implementation, the order would not be user-defined. It would be
deterministic though. If the implementation of Map.of or the hash code
of the objects a user stores there were to suddenly change, the order
could change too.

Be it Map.of or HashMap, there's no user-defined order. The only
user-defined order one can currently get is by using LinkedHashMap. In
the future though, we may get SequencedMap.of.

On Fri, Sep 5, 2025 at 4:52 PM Ryan Ernst <ryan at iernst.net> wrote:
>
> The iteration order is deterministic. The problem raised in that thread was that the seed is hidden and uncontrollable.
>
> IMO if you want a Map that has order, use a LinkedHashMap (or the idea is SequencedMap.of is also appealing). However, even if you don’t want to depend on iteration order, sometimes there are bugs that unintentionally depend on that order, so it would still be great to control the seed in order to have reproducibility in tests.
>
> On Sep 5, 2025, at 08:23, Kevin Bourrillion <kevin.bourrillion at oracle.com> wrote:
>
> 
>
> Just as a corroborating data point, it’s banned at my previous company too, and this is a big reason why. Deterministic iteration is a very good thing. (Personal opinion: I’ve come to view non-deterministic iteration as a risky optimization in general, that is usually not called for.)
>
>
>
>
>
> From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Stephen Colebourne <scolebourne at joda.org>
> Date: Friday, September 5, 2025 at 12:13 AM
> To: core-libs-dev <core-libs-dev at openjdk.org>
> Subject: StableValue and non-deterministic iteration order
>
>
> In summary, the current Map.of() is a bit of a hand grenade IMO, and
> something I pretty much banned at my previous company. Which is a
> problem given its key role in StableValue.
>
> Stephen


More information about the core-libs-dev mailing list