A logo showing the text blog.marcnuri.com
Español
Home»Java»Java 10: Testing the new release

Recent Posts

  • Fabric8 Kubernetes Client 7.2 is now available!
  • Connecting to an MCP Server from JavaScript using AI SDK
  • Connecting to an MCP Server from JavaScript using LangChain.js
  • The Future of Developer Tools: Adapting to Machine-Based Developers
  • Connecting to a Model Context Protocol (MCP) Server from Java using LangChain4j

Categories

  • Artificial Intelligence
  • Front-end
  • Go
  • Industry and business
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2015
  • November 2015
  • December 2014
  • March 2014
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Java 10: Testing the new release

2018-03-31 in Java / Legacy tagged Java / Java 10 by Marc Nuri | Last updated: 2023-11-30
Versión en Español

Introduction

Java 10 was released the past 20th of March (2018) following the new tight six-month release schedule. This version comes just after the Java 9 release on September 2017 and marks this past release obsolete. Same will happen to Java 10 on September this year, when the release of Java 11 will mark this one obsolete.

Java 11 will be released as a long term support (LTS) version and will have a much longer lifespan, but until then, let’s take a look at some of the new features in Java 10.

Time-Based Release Versioning

Java 10 introduces the new time-based release versioning (JEP 322) which is a recast of JEP 223 delivered on Java 9 to enable the new release model. From now on version numbers will follow this pattern:

$FEATURE.$INTERIM.$UPDATE.$PATCH

Every six months a new feature version will be released, every three years starting on September 2018 the feature release will be a long-term support release.

A diagram of the new JDK Release model
A diagram of the new JDK Release model

Local-Variable Type Inference

Java 10 includes a bunch of new features, but for most of us the most apparent feature is JEP 286: Local-Variable Type Inference This feature improves the developer experience by removing the boilerplate, necessary until now, to declare local variables expressing the full type fo the variable.

var shouldBeString = "Hello Java 10";
assertTrue(String.class.isInstance(shouldBeString));

From now on, local variables can be declared using the reserved word var, type safety for the variable will be preserved by inferring the variable when its value is first assigned.

So the following code will throw a compilation failure error:

Local-variable type inference
Local-variable type inference

Other features included in this release

  • JEP 296: Consolidate the JDK Forest into a Single Repository
  • JEP 304: Garbage-Collector Interface
  • JEP 307: Parallel Full GC for G1
  • JEP 310: Application Class-Data Sharing
  • JEP 312: Thread-Local Handshakes
  • JEP 313: Remove the Native-Header Generation Tool (javah)
  • JEP 314: Additional Unicode Language-Tag Extensions
  • JEP 316: Heap Allocation on Alternative Memory Devices
  • JEP 317: Experimental Java-Based JIT Compiler
  • JEP 319: Root Certificates

Enhancements in this release

Optional.orElseThrow() Method

An additional orElseThrow() method has been added to the Optional class to replace the standard get() method as the name is confusing because developers won’t expect a getter to throw an exception. From now on this is the preferred alternative and the get() method will be deprecated in future releases.

final Optional<String> optional = Optional.ofNullable("Optional improvement in Java 10");
final String string = optional.orElseThrow(); // Returns OK
final Optional<String> optional = Optional.ofNullable(null);
final String string = optional.orElseThrow(); // Throws NoSuchElementException

Unmodifiable collectors

New methods toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() have been added to the Collectors class to facilitate the creation of unmodifiable collections.

Stream.of(1, 2, 3).collect(Collectors.toUnmodifiableSet());
Stream.of(1, 2, 3).collect(Collectors.toUnmodifiableList());
Stream.of(1, 2, 3).collect(Collectors.toUnmodifiableMap(Function.identity(), Function.identity()));

Source code

You can find the full source code for this article with tests for the new features and enhancements at GitHub.

Java 10
Java 10
Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Post navigation
Spring Bean Scopes: Guide to understand the different Bean scopesJava 8 Streams: Convert List into Map
© 2007 - 2025 Marc Nuri