java1.8 "_" 保留关键字有什么用

what use for java1.8 "_" reserved keyword

如题,java1.8保留“_”字,有什么用?

消息:- '_' 不应用作标识符,因为它是源代码级别的保留关键字

在 Java SE 7 及更高版本中,任意数量的下划线字符 (_) 可以出现在数字文字中数字之间的任何位置。此功能使您能够分隔数字文字中的数字组,这可以提高代码的可读性。

例如,如果您的代码包含多位数的数字,您可以使用下划线字符将数字分成三组,类似于使用逗号或 space, 作为分隔符。

以下示例展示了在数字文字中使用下划线的其他方式:

long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;

注意:只能在数字之间放置下划线。

以下地方不能加下划线:

  • 数字的开头或结尾
  • 在浮点字面量中与小数点相邻
  • FDL 后缀之前
  • 在需要一串数字的位置

以下是下划线放置的一些有效和无效示例:

float pi1 = 3_.1415F;      // Invalid; cannot put underscores adjacent to a decimal point
float pi2 = 3._1415F;      // Invalid; cannot put underscores adjacent to a decimal point

int x1 = _52;              // This is an identifier, not a numeric literal
int x2 = 5_2;              // OK (decimal literal)
int x3 = 52_;              // Invalid; cannot put underscores at the end of a literal
int x4 = 5_______2;        // OK (decimal literal)

希望这能满足您的要求。