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

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

PHPz
PHPzforward
2023-09-09 14:49:021411browse

在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(_);
   }
}

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>

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete