<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Stable Map Background</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
The iteration order of `StableValue.map()` is not specified, and the returned map is not an instance of
<code>SequencedMap</code>. The current implementation happens to rely on <code>Map.of()</code> for which the iteration order of mappings is specified to be unspecified and subject to change (i.e., indeterministic). This was a deliberate design choice. Hence,
 StableValue.map() currently has the same iteration order properties as Map.of().</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
The Way Forward for Stable Map<br>
There are several alternatives for the future, all of which have different pros and cons, including but not limited to, and in no particular order (pun not intended):<br>
 * The iteration order remains unspecified as today (and could be fixed/random/always having 42 at the front/...),<br>
 * We specify that the order is unspecified and subject to change (like Map.of()),<br>
 * We specify that the order is unspecified but will always remain the same (i.e., not subject to change/is deterministic),<br>
 * We specify that the order is specified and coincides with the iteration order of the given Set at construction time, or<br>
 * We allow the client to provide a Comparator that decides the iteration order<br>
<br>
I think there is a more general discussion to be had that should be aligned with the direction of the immutable collections and any potential constructs with deterministic order there.</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Best, Per</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Archie Cobbs <archie.cobbs@gmail.com><br>
<b>Sent:</b> Friday, September 5, 2025 10:50 PM<br>
<b>To:</b> Pavel Rappo <pavel.rappo@gmail.com><br>
<b>Cc:</b> Ryan Ernst <ryan@iernst.net>; Kevin Bourrillion <kevin.bourrillion@oracle.com>; Stephen Colebourne <scolebourne@joda.org>; core-libs-dev <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: StableValue and non-deterministic iteration order</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr">On Fri, Sep 5, 2025 at 3:32 PM Pavel Rappo <<a href="mailto:pavel.rappo@gmail.com">pavel.rappo@gmail.com</a>> wrote:</div>
<div class="x_gmail_quote x_gmail_quote_container">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
Be it Map.of or HashMap, there's no user-defined order. The only<br>
user-defined order one can currently get is by using LinkedHashMap. In<br>
the future though, we may get SequencedMap.of. </blockquote>
</div>
<div><br>
</div>
<div>I vote for adding <span style="font-family:monospace">SequencedMap.of()</span>. That seems like a good solution to the problem at hand, as well as a generally useful addition.</div>
<div><br>
</div>
<div>Of course if you believe that argument, then <span style="font-family:monospace">SequencedSet.of()</span> would also be a good addition, since <span style="font-family:monospace">Set.of()</span> also makes no ordering guarantees.</div>
<div><br>
</div>
<div>-Archie</div>
<br>
<span class="x_gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="x_gmail_signature">Archie L. Cobbs<br>
</div>
</div>
</div>
</body>
</html>