On Tue, 8 Feb 2022 17:23:38 GMT, Stuart Marks <sma...@openjdk.org> wrote:
> PR for Sequenced Collections implementation. Yes, I think this `LinkedHashMap.keySet()` change is binary compatible but source incompatible. Surely binary incompatibility would have been enough to rule it out immediately. For the source compatibility question, I found at least these four examples that it would break, using [this SourceGraph query](https://sourcegraph.com/search?q=context:global+extends+LinkedHashMap+AND+keySet%28%29+%7B&patternType=literal): * [`ConcurrentModificationThrowingMap`](https://sourcegraph.com/github.com/spring-projects/spring-boot/-/blob/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySourceTests.java?L288:17&subtree=true) (in a test) * [`GroupedMap`](https://sourcegraph.com/github.com/dromara/hutool/-/blob/hutool-setting/src/main/java/cn/hutool/setting/GroupedMap.java?L230) * [`BoundedConcurrentHashMap`](https://sourcegraph.com/github.com/debezium/debezium/-/blob/debezium-core/src/main/java/io/debezium/util/BoundedConcurrentHashMap.java?L2100:19-2100:25) * [`NutMap`](https://sourcegraph.com/github.com/nutzam/nutz/-/blob/src/org/nutz/lang/util/NutMap.java?L354:24-354:30) So while probably not very widespread, there are certainly examples that this will break. (I didn't find any examples in Google's internal source base.) Perhaps instead `LinkedHashMap<K, V>` should acquire a new method `SequencedSet<K> sequencedKeySet()`. Or perhaps `SequencedMap<K, V>` should acquire that method. I'm sure you've noticed the parallel with `NavigableMap.navigableKeySet()`. Unlike `NavigableMap`, it would also be straightforward to understand `SequencedSet<Map.Entry<K, V>> sequencedEntrySet()`. src/java.base/share/classes/java/util/LinkedHashMap.java line 604: > 602: * @return a set view of the keys contained in this map > 603: */ > 604: public SequencedSet<K> keySet() { Changing the return type means that subclasses of `LinkedHashMap` that override `keySet()` will no longer compile, unless they also change the return type. ------------- PR Comment: https://git.openjdk.org/jdk/pull/7387#issuecomment-1098605810 PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r848817204