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. 

Also, technically, there is a way to change the return type in a binary 
compatible way ... if union types are supported in the language. 
In that case, Set.of() can be declared like this 

static <E> Set<E> | SequenceSet<E> of(E... ) { 
... 
} 

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 . 

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. 

Rémi 

> From: "joe darcy" <joe.da...@oracle.com>
> To: "core-libs-dev" <core-libs-dev@openjdk.org>
> Sent: Friday, January 17, 2025 6:30:40 PM
> Subject: Re: Factory methods for SequencedSet and SequencedMap

> On 1/16/2025 11:26 PM, Rafael Winterhalter wrote:

>> Would it even be possible to change the return types of Set.of(...) and
>> Map.of(...) without breaking binary compatibility?

> In short, no.
[...] 

> -Joe
Rémi 

Reply via email to