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 ...