On Mon, 22 Sep 2025 06:54:36 GMT, Tagir F. Valeev <[email protected]> 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

Reply via email to