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

Recent Posts

  • Fabric8 Kubernetes Client 6.5.0 is now available!
  • Eclipse JKube 1.11 is now available!
  • Fabric8 Kubernetes Client 6.4.1 is now available!
  • I bought an iPad
  • Three years at Red Hat

Categories

  • Front-end
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 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
  • 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
  • December 2015
  • November 2015
  • November 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: 2021-03-21
Versión en Español

Introduction

As you probably already know, Java 10 was released the past 20th of March 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 allow 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.

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 features improves the developer experience by removing the boilerplate, necessary until now, to declare local variables expressing the full type fo the variable.

1var shouldBeString = "Hello Java 10";
2assertTrue(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

  • 296: Consolidate the JDK Forest into a Single Repository
  • 304: Garbage-Collector Interface
  • 307: Parallel Full GC for G1
  • 310: Application Class-Data Sharing
  • 312: Thread-Local Handshakes
  • 313: Remove the Native-Header Generation Tool (javah)
  • 314: Additional Unicode Language-Tag Extensions
  • 316: Heap Allocation on Alternative Memory Devices
  • 317: Experimental Java-Based JIT Compiler
  • 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. Form now on this is the preferred alternative and the get() method will be deprecated in future releases.

1final Optional<String> optional = Optional.ofNullable("Optional improvement in Java 10");
2final String string = optional.orElseThrow(); // Returns OK
3final Optional<String> optional = Optional.ofNullable(null);
4final 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.

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

Sourcecode

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 - 2023 Marc Nuri