Java中的新关键字9 [英] New Keywords in Java 9
问题描述
Java 9最大的功能之一将是Project Jigsaw定义的模块系统。从项目拼图中阅读幻灯片时:在JavaOne 2015的Hood 下,我注意到以下源代码:
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;
}
这里有趣的是文件以<$ c $结尾c> .java 并且似乎使用了两个新关键字: module
, exports
。在Java 9中将引入哪些其他关键字?如何处理向后兼容性(即名为 module
的函数或变量)?
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
)?
推荐答案
在Java 9中为模块声明添加的关键字总结在 Java语言规范,Java SE 9
版:
The keywords added for module declarations in Java 9 are summarized in §3.9 of the Java Language Specification, Java SE 9 Edition:
另外十个字符序列是受限制的关键字:
open
,
module
,需要
,传递
,exports
,打开
,到
,使用
,
提供
和with
。这些字符序列被标记为
关键字,它们在ModuleDeclaration
和ModuleDirective产品(第7.7节)中显示为终端。它们在其他地方被标记为
标识符,以便与Java SE 9之前写入
的程序兼容。有一个例外:在ModuleDirective生产中,字符序列的右边
需要立即生成,
将字符序列传递标记为关键字,除非
后跟分隔符,在这种情况下,它被标记为
标识符。
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.
如果您目前有一个名为 module
的方法,或此处列出的任何其他
关键字,它将继续编译。
If you presently have a method named module
, or any of the other
keywords listed here, it will continue to compile.
(查看
和许可证
是关键字在一个早期的Jigsaw原型中,但
很久以前就被简化了。)
(view
and permits
were keywords in an early Jigsaw prototype, but
they were simplified out of existence long ago.)
这篇关于Java中的新关键字9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!