UniJ: Universal JDK 9+ API Facade
UniJ targets JDK 8 and is a facade of:
Collectorproviders (equivalent to those introduced in JDK 9+)
UniJ provides a facade of above-mentioned methods in a similar way that SLF4J (Simple Logging Facade for Java) provides a facade of logging. In both cases, there is an API that can be implemented in many different ways and then be injected at runtime as a Java service.
UniJ consists of three key parts described further on: its API, its bindings, and its bundles.
Note: if you look for a specific UniJ project, consult UniJ project layout.
UniJ is to new parts of JDK 9+ API what SLF4J is to logging API — a facade.
Set<Integer> set = Set.of(1, 2); List<Integer> list = List.of(1, 2, 1); Map<Integer, String> map = Map.of(1, "a", 2, "b"); Set.copyOf(list); // ⇒ [1, 2] Set.of(1, 2, 1); // throws "duplicate element" exception Set.of(1, 2, null); // throws null-pointer exception
UniJ (JDK 8+)
Set<Integer> set = UniSets.of(1, 2); List<Integer> list = UniLists.of(1, 2, 1); Map<Integer, String> map = UniMaps.of(1, "a", 2, "b"); UniSets.copyOf(list); // ⇒ [1, 2] UniSets.of(1, 2, 1); // throws "duplicate element" exception UniSets.of(1, 2, null); // throws null-pointer exception
UniJ is meant only as a facade of the official JDK APIs. UniJ will not introduce any APIs of its own design. UniJ may only introduce new APIs that directly correspond to APIs in the latest stable release of the JDK (currently, it's JDK 13).
UniJ is also a partial:
|JDK 9+||UniJ (JDK 8+)|
|type||static method name||type|
This library has been designed primarily for:
End Users Stuck on JDK 8
If you're stuck on JDK 8, you can't use JDK 9+'s new methods like
However, by adding a dependency on a UniJ bundle of your choosing (plus some optional extra dependencies), you can enjoy a JDK 11-like API on JDK 8!
Libraries Targeting JDK 8
If you maintain a library targeting JDK 8, you can't use JDK 9+'s new methods like
However, by adding a dependency on UniJ User API, you can program to JDK 11-like API!
Note: your users will have to provide implementations of the above-mentioned API (as per Usage for End Users).
UniJ has two kind of APIs:
- User API: utility classes (this is what the user interacts with)
- Service API: interfaces (this is what the service provider implements)
The call chain looks as follows:
end user ⟷ User API ⟷ Service API ⟷ service provider
This API has strict equivalence to the corresponding JDK API (see API Specification for details).
Disclaimer: As an end user, you don't need to be concerned with this API.
UniJ Service API is defined in
and consists of the following interfaces:
A module providing implementations of one or more of these interfaces constitutes a binding.
UniJ APIs come with a detailed specification for the Service API interfaces. The specification is based on the contract of the original JDK API (expressed mostly in JavaDoc), and tries to follow it as close as possible.
The focal points of the specification are:
- duplicate handling (e.g. no duplicates allowed in
- consistency (e.g. only one empty collection instance)
Read the source of the Spock tests linked above to see what every UniJ binding guarantees.
A binding is simply a library with implementation(s) of the Service API.
UniJ comes with a number of predefined bindings, which can all be found under
Collection Factory API Bindings
UniJ currently provides four types of
Collection factory API bindings:
simply forwards all calls to the JDK
Miscellaneous API Bindings
UniJ currently provides two types of miscellaneous API bindings:
simply forwards all calls to the JDK
provides custom implementations based on the ones in JDK 11
Instead of any of the predefined bindings mentioned above, you can create and depend on a custom binding.
A UniJ bundle is a module having no source (save for its
module-info.java) and depending on the following three modules:
pl.tlinkowski.unij.apimodule (transitive dependency)
Collectionfactory API binding (= one of
- miscellaneous API binding (= one of
Currently, UniJ provides the following four bundles:
JDK 11 bundle (
pl.tlinkowski.unij.bundle.jdk11), made of:
pure JDK 8 bundle (
pl.tlinkowski.unij.bundle.jdk8), made of:
Guava on JDK 8 bundle (
pl.tlinkowski.unij.bundle.guava_jdk8), made of:
Eclipse Collections on JDK 8 bundle (
pl.tlinkowski.unij.bundle.eclipse_jdk8), made of:
See Usage document.
See Extra Information document.
Questions & Answers
See Q&A document.
See Changelog document.
Usage: JDK 8+.
Building: Gradle 5+, JDK 11+.