gpt4 book ai didi

java - 数字文字中的下划线

转载 作者:行者123 更新时间:2023-11-29 03:50:39 28 4
gpt4 key购买 nike

官方Java site我遇到了这条线

    you cannot place underscores in the following places:

At the beginning or end of a number...

他们也给出了例子

int x1 = _52;              // This is an identifier, not a numeric literal

当我在我的代码中使用它时,它没有给出任何编译时错误

long l = _23L;      

我们可以在开头使用_吗?

是什么意思
This is an identifier, not a numeric literal

如果这是一个非常愚蠢的问题,我很抱歉,我已经很久没有复习 Java 基础知识了。

编辑:
我正在使用 Windows XP 和 Java 7

java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

最佳答案

文字 是您在代码中硬编码的任何内容,例如:

int x  = 10;
String str = "hello";

在这个 10hello 中是文字。

所以 numeric literal 只不过是具有数值的文字。

标识符是赋予对象、类等的名称,但不能是关键字,如 int、boolean、null 等。

因此在上面的示例中,x、str 和 String 是标识符。

旁注:从 JDK 6 到 JDK 7,定义数字字面量的方式不同。因此,有问题的代码将仅在 JDK7 上运行

关于java - 数字文字中的下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8958522/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com