下划线在Java数字中不可见

-14 java

下划线在整数数据类型中不可见:

int intHex = 0x0041;
System.out.println("intHex: " + intHex);
int intBinary = 0b01000001;
System.out.println("intBinary: " + intBinary);
int intUnderscore = 1_23_456;
System.out.println("intUnderscore: " + intUnderscore);
Run Code Online (Sandbox Code Playgroud)

小智 5

如果您期望

int intUnderscore = 1_23_456;
System.out.println("intUnderscore: " + intUnderscore);
Run Code Online (Sandbox Code Playgroud)

版画

intUnderscore: 1_23_456
Run Code Online (Sandbox Code Playgroud)

您误解了下划线的目的。它只是语法糖,旨在使源代码更易于阅读。