gpt4 book ai didi

java - Java 9 中的新关键字

转载 作者:IT老高 更新时间:2023-10-28 20:51:25 24 4
gpt4 key购买 nike

Java 9 最大的特性之一将是由 Project Jigsaw 定义的模块系统。从 Project Jigsaw: Under the Hood 阅读幻灯片时在 JavaOne 2015 上,我注意到以下源代码:

// src/java.sql/module-info.java
module java.sql {
exports java.sql;
exports javax.sql;
exports javax.transaction.xa;
}

我感兴趣的是文件以 .java 结尾,并且似乎使用了两个新关键字:moduleexports . Java 9 中还会引入哪些其他关键字?如何处理向后兼容性(即名为 module 的函数或变量)?

最佳答案

Java 9 中为模块声明添加的关键字总结在Java Language Specification, Java SE 9Edition的§3.9 :

A further ten character sequences are restricted keywords: open, module, requires, transitive, exports, opens, to, uses, provides, and with. 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 的方法,或者任何其他的此处列出的关键字,它将继续编译。

(viewpermits 是早期 Jigsaw 原型(prototype)中的关键字,但它们在很久以前就被简化了。)

关于java - Java 9 中的新关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36322223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com