Java 10, released in March 2018, introduced several significant features and enhancements,
with the most notable for developers being Local-Variable Type Inference.1
Here are the key features of Java 10:
1. Local-Variable Type Inference (JEP 286)
This feature allows you to use the keyword var to declare local variables without explicitly
specifying their type.2 The compiler infers the type from the initializer.3
● Before Java 10:
Java
List<String> list = new ArrayList<String>();
● Java 10 and later:
Java
var list = new ArrayList<String>();
// 'list' is inferred as List<String>
This is limited to local variables with initializers, indices in traditional and enhanced for
loops, and locals declared in a for loop. It cannot be used for fields, method parameters, or
method return types.
2. Unmodifiable Collections Enhancements4
New static methods were added to create unmodifiable copies of existing collections.5
● List.copyOf(Collection), Set.copyOf(Collection), and Map.copyOf(Map): These
methods create new, unmodifiable collection instances from existing ones.6 Any
subsequent modification to the original collection will not affect the returned
unmodifiable copy.7
● Stream Collectors for Unmodifiable Collections: New methods in the Collectors class
allow collecting stream elements directly into unmodifiable lists, sets, and maps:8
○ Collectors.toUnmodifiableList()
○ Collectors.toUnmodifiableSet()
○ Collectors.toUnmodifiableMap()
3. Optional.orElseThrow()
A new method, orElseThrow(), was added to Optional, OptionalInt, OptionalLong, and
OptionalDouble. 9This is considered a preferred, semantically clearer alternative to the
existing get() method, as its name more clearly suggests it may throw an exception if the
value is not present.10
4. Performance and Internal Enhancements
Several changes primarily benefit the performance, maintenance, and architecture of the
JVM:
● Parallel Full GC for G1 (JEP 307): Improved the Garbage-First (G1) Garbage Collector
by making the full garbage collection phase parallel, which can reduce the worst-case
latency of a full GC.11
● Application Class-Data Sharing (AppCDS) (JEP 310): Extends Class-Data Sharing
(CDS) to allow application classes to be placed in the shared archive, significantly
reducing startup time and memory footprint, especially for small applications or those
running in containers.12
● Garbage-Collector Interface (JEP 304): Introduced a clean interface for Garbage
Collectors within the JVM source code, improving modularity and maintainability of the
internal GC code.13
5. Container Awareness
The JVM became more aware of being run inside a Docker container, improving the automatic
detection of resource limits (like CPU and memory) set by the container.14 This helps the JVM
make more informed decisions about thread usage and heap size.
6. Time-Based Release Versioning (JEP 322)15
Java 10 formalized the new time-based release model, where a new feature release is
delivered every six months (March and September).16 The versioning scheme was also
updated to reflect this cadence. Java 10 was the first non-LTS (Long Term Support) feature
release under this new model.