In earlier versions of Java, the underscore ("_") has been used as the identifierOr create variable name. Starting with Java 9, the underscore character is a reserved keyword and cannot be used as an identifier or variable name. If we use a single underscore character as an identifier, the program will fail to compile and throw a compile-time error because now it is a keyword, and cannot be used as a variable name in Java 9 or later.
public class UnderscoreKeywordTest { public static void main(String args[]) { int _ = 50 System.out.println(_); } }
<strong>UnderscoreKeywordTest.java:3: error: as of release 9, '_' is a keyword, and may not be used as an identifier int _ = 50; ^ UnderscoreKeywordTest.java:4: error: as of release 9, '_' is a keyword, and may not be used as an identifier System.out.println(_);</strong>
The above is the detailed content of What is the purpose of the underscore keyword in Java 9?. For more information, please follow other related articles on the PHP Chinese website!