<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div><br></div><div><br></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Rafael Winterhalter" <rafael.wth@gmail.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"core-libs-dev" <core-libs-dev@openjdk.org>, "joe darcy" <joe.darcy@oracle.com><br><b>Sent: </b>Tuesday, January 21, 2025 10:17:35 AM<br><b>Subject: </b>Re: Factory methods for SequencedSet and SequencedMap<br></blockquote></div><div data-marker="__QUOTED_TEXT__"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><div>Wouldn't this already be possible with today's union types?</div><br><div>static <E, S extends Set<E> & SequencedSet<E>> S of(E... elements) { ... }</div></div></blockquote><div><br></div><div>No, because when you have a type variable declared on a method, it means \forall,<br data-mce-bogus="1"></div><div>so here, the method of() has to work for all implementations of S, so all implementations of a SeqenceSet.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>To see the issue, you can fix the type argument, by example<br data-mce-bogus="1"></div><div> TreeSet<String> set = Set.<String, TreeSet<String>>of("foo")<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>is obviously wrong but allowed by the declaration.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><br><div>Then again, I do not think that the regular Set and Map implementations should be sequenced, mainly to avoid that tests suffer from this sequencing.</div></div></blockquote><div><br></div><div>I do not disagree :)<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir="ltr"><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Am So., 19. Jan. 2025 um 16:18 Uhr schrieb Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div>What can be done is to have Set.of()/Map.of() to delegate to SequenceSet.of()/SequenceMap.of() so there is only one implementation at runtime.<br></div><br><div>Also, technically, there is a way to change the return type in a binary compatible way ... if union types are supported in the language.<br></div><div>In that case, Set.of() can be declared like this<br></div><br><div> static <E> Set<E> | SequenceSet<E> of(E... ) {<br></div><div> ...<br></div><div> }<br></div><br><div>because of erasure, the binary descriptor will use Set, but the Signature will be Set<E> | SequenceSet<E> so the compiler will see the return type as a SequencedSet .<br></div><br><div>Obviously, union types is a far bigger features than adding SequenceSet/SequenceMap so it's a big if, but it may happen in the future.<br></div><br><div>Rémi</div><br><hr id="m_6250510832610766535zwchr"><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"joe darcy" <<a href="mailto:joe.darcy@oracle.com" target="_blank">joe.darcy@oracle.com</a>><br><b>To: </b>"core-libs-dev" <<a href="mailto:core-libs-dev@openjdk.org" target="_blank">core-libs-dev@openjdk.org</a>><br><b>Sent: </b>Friday, January 17, 2025 6:30:40 PM<br><b>Subject: </b>Re: Factory methods for SequencedSet and SequencedMap<br></blockquote></div><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div>On 1/16/2025 11:26 PM, Rafael
Winterhalter wrote:<br>
</div>
<blockquote>
<div dir="ltr">
<div>Would it even be possible to change the return types of
Set.of(...) and Map.of(...) without breaking binary
compatibility?</div>
</div>
</blockquote>
<p><br>
</p>
<p>In short, no.</p></blockquote><br><div>[...]</div><br><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><p><br>
</p>
<p>-Joe</p></blockquote><br><div>Rémi</div></div></div></div></blockquote></div><br></blockquote></div></div></body></html>