0

New Java 9 Keywords

A module system specified by Project Jigsaw will be one of Java 9's most significant additions. I spotted the following source code when reading Project Jigsaw: Under the Hood presentations at JavaOne 2015: // src/java.sql/module-info.java module java.sql { exports java.sql; exports javax.sql; exports javax.transaction.xa; } What interests me about this file is that it ends in.java and appears to employ two new keywords: module and exports. What new keywords will be included in Java 9? How will backward compatibility (i.e. functions or variables called module) be handled? After searching it online I found keywords added for module declarations in Java 9 are summarized here. https://www.scaler.com/topics/new-keyword-in-java/

23rd Nov 2022, 9:38 AM
sarthak jain
sarthak jain - avatar
1 Odpowiedź
+ 2
What you referred is a module descriptor file. Strictly speaking it is not directly compiled to Java bytecode, but it is a special configuration file that describes the dependencies and permissions between different parts of your program. The keywords "module", "requires" and "exports", are actually in the category of reserved identifiers, and in some context they can still be used, for example you can still have a variable called module. However, in Java 9, the single underscore character _ was added as a keyword with special meaning, so you cannot use this as variable name any more. https://en.m.wikipedia.org/wiki/List_of_Java_keywords Java language designers are taking a lot of care to preserve backwards compatibility, so adding new keywords is extremely rare. Even in more recent features such as pattern matching, the syntax is reusing some existing keywords in new ways inside the switch statement.
30th Dec 2022, 4:59 PM
Tibor Santa
Tibor Santa - avatar