© Fu Cheng 2018
Fu ChengExploring Java 9https://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().
public interface SayHi {
  private String buildMessage() {
    return "Hello";
  }
  void sayHi(final String message);
  default void sayHi() {
    sayHi(buildMessage());
  }
}
Listing 16-1.
Private Interface Methods

Resource References in try-with-resources

The try-with-resources ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.