<html><body><div dir="ltr"><div style="">
</div><div style=""><div>
<div dir="ltr">If you need order using List instead of Set/Map is perfectly fine decision of your students. It’s good if they learn that early. :)</div>
<div id="ms-outlook-mobile-signature"><div><br></div><div><br></div><div style="direction:ltr">-- </div><div style="direction:ltr">http://bernd.eckenfels.net</div></div>
</div>
<div> </div><hr style="display:inline-block;width:98%" tabindex="-1"><div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>Von:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> im Auftrag von Remi Forax <forax@univ-mlv.fr><br><b>Gesendet:</b> Sonntag, März 26, 2023 1:42 PM<br><b>An:</b> Jens Lideström <jens@lidestrom.se><br><b>Cc:</b> core-libs-dev <core-libs-dev@openjdk.org><br><b>Betreff:</b> Re: The non-deterministic iteration order of Immutable Collections<div> </div></font></div>----- Original Message -----
<br>> From: "Jens Lideström" <jens@lidestrom.se>
<br>> To: "core-libs-dev" <core-libs-dev@openjdk.org>
<br>> Sent: Sunday, March 26, 2023 11:38:07 AM
<br>> Subject: Re: The non-deterministic iteration order of Immutable Collections
<br>
<br>> I think Map#of and friends would be more useful and less error prone if they
<br>> where to return collections that have a fixed iteration order, where the order
<br>> is defined by the insertion order when the map is created.
<br>
<br>I agree.
<br>
<br>They are several use cases for Set.of()/Map.of(), for testing you want them to not have an order but for a defensive copy (Set.copyOf()/Map.copyOf()) you want them to keep the order. Currently, the implementation rotates toward the former instead of the later.
<br>
<br>A lot of my students struggle with the semantics of Set.of()/Map.of() because this choice makes the unmodifiable set/map not beginners friendly.
<br>To the point where a student will prefer to use a List instead of a Set, because List.copyOf() seems to work "correctly" compared to Set.copyOf().
<br>
<br>Python 3.7 has changed the implementation of its set and dictionaries to keep the insertion order for this exact reason.
<br>
<br>Java could do the same.
<br>
<br>regards,
<br>Rémi
<br>
<br></div></div></body></html>