RFR: 8368178: Add specialization of SequencedCollection methods to emptyList, singletonList and nCopies [v2]
Per Minborg
pminborg at openjdk.org
Mon Sep 22 07:24:48 UTC 2025
On Mon, 22 Sep 2025 06:54:36 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
>> In theory, `EmptyList` and `SingletonList` could implement `SequencedCollection`. Same for map.
>
> @minborg `EmptyList` already implements it, as any other `List`:
>
> public interface List<E> extends SequencedCollection<E> { ... }
>
>
> For `EmptyMap` (and even `SingletonMap` and `SingletonSet`), it's possible, but it will require changing the public interface (`Collections::emptyMap` will have to return `SequencedMap`), which may produce binary compatibility issues. Probably we can invent a binary-compatible signature like this:
>
>
> public static final <K,V,M extends Map<K, V> & SequencedMap<K, V>> M emptyMap() { ... }
>
> But it looks ugly.
@amaembo `SequencedMap` already implements `Map`. :-) So, we could say:
public static final <K,V> SequencedMap<K, V> emptyMap() { ... }
An empty map could also "incidentally" implement `SequencedMap`.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27406#issuecomment-3317317689
More information about the core-libs-dev
mailing list