© Fu Cheng 2018

Fu Cheng, Exploring Java 9, https://doi.org/10.1007/978-1-4842-3330-6_16

16. Miscellaneous

Fu Cheng

(1)Auckland, New Zealand

This chapter covers various changes in Java 9.

Small Language Changes

Java 9 has added some small language changes.

Private Interface Methods

It’s now possible to add private methods to interfaces in Java 9. The interface SayHi in Listing 16-1 has the private method buildMessage() to generate the default message to use in the default method sayHi().

Listing 16-1. Private Interface Methods
public interface SayHi {  private String buildMessage() {    return "Hello";  }  void sayHi(final String message);  default void sayHi() {    sayHi(buildMessage());  }}

Resource References in try-with-resources

The try-with-resources ...

Get Exploring Java 9: Build Modularized Applications in Java now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.