9 Small Language Changes in Java SE 9
There are several small language changes in Java SE 9.
@SafeVarargs annotation is allowed on private instance methods.
The @SafeVarargs annotation can be applied only to methods that cannot be overridden. These include static methods, final instance methods, and, new in Java SE 9, private instance methods.
You can use diamond syntax in conjunction with anonymous inner classes.
Types that can be written in a Java program, such as int
or String
, are called denotable types. The compiler-internal types that cannot be written in a Java program are called non-denotable types.
Non-denotable types can occur as the result of the inference used by the diamond operator. Because the inferred type using diamond with an anonymous class constructor could be outside of the set of types supported by the signature attribute in class files, using the diamond with anonymous classes was not allowed in Java SE 7.
In Java SE 9, as long as the inferred type is denotable, you can use the diamond operator when you create an anonymous inner class.
The underscore character is not a legal name.
If you use the underscore character ("_") an identifier, your source code can no longer be compiled.
Private interface methods are supported.
Private interface methods are supported. This support allows nonabstract methods of an interface to share code between them.