允许在整数数字之间使用下划线的理由是什么?
What was the rationale for allowing underscores between integer digits?
我今天在 JLS 3.10.1 (integer literals) 部分偶然发现了这个看似奇怪的陈述:
Underscores are allowed as separators between digits that denote the integer.
你瞧,以下是完全有效的 (example):
int x = 1_2_3_4_5____6;
下划线只能出现在位之间,leading/trailing下划线无效。
这样做的理由是什么?它是其他语言的遗留物吗?当时流行的一些风格?允许似乎是一件很奇怪的事情。
这背后的想法是能够显示一个易于阅读的大数字。
示例:int x = 1_000_000;
还有其他用例,但我认为这是最常用的。
有关详细信息,请参阅 the documentation。
我今天在 JLS 3.10.1 (integer literals) 部分偶然发现了这个看似奇怪的陈述:
Underscores are allowed as separators between digits that denote the integer.
你瞧,以下是完全有效的 (example):
int x = 1_2_3_4_5____6;
下划线只能出现在位之间,leading/trailing下划线无效。
这样做的理由是什么?它是其他语言的遗留物吗?当时流行的一些风格?允许似乎是一件很奇怪的事情。
这背后的想法是能够显示一个易于阅读的大数字。
示例:int x = 1_000_000;
还有其他用例,但我认为这是最常用的。
有关详细信息,请参阅 the documentation。