2 Java Language Changes
This section summarizes the updated language features in Java SE 9 and subsequent releases.
Java Language Changes for Java SE 11
Feature | Description | JEP |
---|---|---|
Introduced in Java SE 10. In this release, it has been enhanced with
support for allowing Local-Variable Type Inference extends type inference to declarations of local variables with initializers. |
Java Language Changes for Java SE 10
Feature | Description | JEP |
---|---|---|
Introduced in this release. Local-Variable Type Inference extends type inference to declarations of local variables with initializers. |
JEP 286: Local-Variable Type Inference |
Java Language Changes for Java SE 9
Feature | Description | JEP |
---|---|---|
Java Platform module system, see Project Jigsaw on OpenJDK. |
Introduced in this release. The Java Platform module system introduces a new kind of Java programing component, the module, which is a named, self-describing collection of code and data. Its code is organized as a set of packages containing types, that is, Java classes and interfaces; its data includes resources and other kinds of static information. Modules can either export or encapsulate packages, and they express dependencies on other modules explicitly. |
|
Small language enhancements (Project Coin): |
Introduced in Java SE 7 as Project Coin. It has been enhanced with a few amendments. |
JSR 334: Small Enhancements to the Java Programming Language |
More Concise try-with-resources Statements
If you already have a resource as a final
or effectively final
variable, you can use that variable in a try-with-resources
statement without declaring a new variable. An "effectively final" variable is one whose value is never changed after it is initialized.
For example, you declared these two resources:
// A final resource
final Resource resource1 = new Resource("resource1");
// An effectively final resource
Resource resource2 = new Resource("resource2");
In Java SE 7 or 8, you would declare new variables, like this:
try (Resource r1 = resource1;
Resource r2 = resource2) {
...
}
In Java SE 9, you don’t need to declare r1
and r2
:
// New and improved try-with-resources statement in Java SE 9
try (resource1;
resource2) {
...
}
There is a more complete description of the try-with-resources statement in The Java Tutorials (Java SE 8 and earlier).
@SafeVarargs Annotation Allowed on Private Instance Methods
The @SafeVarargs
annotation is allowed on private instance
methods. It 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.
Diamond Syntax and Anonymous Inner Classes
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.