Adopting SequencedCollection via multi-release jars?

Fabian Meumertzheim fabian at buildbuddy.io
Tue Feb 4 16:36:26 UTC 2025


Guava provides immutable collections such as ImmutableList that are
naturally sequenced. It would be useful to integrate it with Java 21's
SequencedCollection interface. However, Guava needs to keep supporting
Java 11 for the foreseeable future.

An idea that may allow Guava to remain compatible but still adopt
SequencedCollection today would be to have classes implement a
vendored and renamed version of the SequencedCollection interface and
"override" it with an interface that extends the actual
SequencedCollection interface in the 21 subdirectory of a
multi-release JAR. However, the JAR specification states that:

"The public API exported by the classes in a multi-release JAR file
must be exactly the same across versions, ..."

Would the public API be considered to be identical in the case where
only the hierarchy of implemented interfaces changes? If not, is there
another supported way for a class to start implementing
SequencedCollection while remaining compatible with JDK versions that
don't provide the interface yet?

Best,
Fabian


More information about the core-libs-dev mailing list