One of Java 9's largest features will be a module system defined by Project Jigsaw. When reading slides from the Project Jigsaw: Under the Hood at JavaOne 2015, I noticed the following source code:
// src/java.sql/module-info.java
module java.sql {
exports java.sql;
exports javax.sql;
exports javax.transaction.xa;
}
What is interesting here to me is that the file ends in .java
and seems to use two new keywords: module
, and exports
. What other keywords will be introduced in Java 9? How will backwards compatibility be dealt with (i.e. functions or variables named module
)?
The keywords added for module declarations in Java 9 are summarized in §3.9 of the Java Language Specification, Java SE 9 Edition:
A further ten character sequences are restricted keywords:
open
,module
,requires
,transitive
,exports
,opens
,to
,uses
,provides
, andwith
. These character sequences are tokenized as keywords solely where they appear as terminals in the ModuleDeclaration and ModuleDirective productions (§7.7). They are tokenized as identifiers everywhere else, for compatibility with programs written prior to Java SE 9. There is one exception: immediately to the right of the character sequence requires in the ModuleDirective production, the character sequence transitive is tokenized as a keyword unless it is followed by a separator, in which case it is tokenized as an identifier.
If you presently have a method named module
, or any of the other
keywords listed here, it will continue to compile.
(view
and permits
were keywords in an early Jigsaw prototype, but
they were simplified out of existence long ago.)