Home > Java > javaTutorial > What is the purpose of the underscore keyword in Java 9?

What is the purpose of the underscore keyword in Java 9?

PHPz
Release: 2023-09-09 14:49:02
forward
1460 people have browsed it

在Java 9中,下划线关键字的用途是什么?

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.

Example

public class UnderscoreKeywordTest {
   public static void main(String args[]) {
      int _ = 50
      System.out.println(_);
   }
}
Copy after login

Output

<strong>UnderscoreKeywordTest.java:3: error: as of release 9, &#39;_&#39; is a keyword, and may not be used as an identifier
int _ = 50;
^
UnderscoreKeywordTest.java:4: error: as of release 9, &#39;_&#39; is a keyword, and may not be used as an identifier
System.out.println(_);</strong>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template