Factory methods for SequencedSet and SequencedMap
Rafael Winterhalter
rafael.wth at gmail.com
Tue Jan 21 09:17:35 UTC 2025
Wouldn't this already be possible with today's union types?
static <E, S extends Set<E> & SequencedSet<E>> S of(E... elements) { ... }
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.
Am So., 19. Jan. 2025 um 16:18 Uhr schrieb Remi Forax <forax at univ-mlv.fr>:
> 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.darcy at oracle.com>
> *To: *"core-libs-dev" <core-libs-dev at 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250121/90311bba/attachment.htm>
More information about the core-libs-dev
mailing list