The literal xyz of type int is out of range(int 类型的字面量 xyz 超出范围)
问题描述
我目前正在使用 Java 中的数据类型,如果我理解正确,类型 long
接受介于 -9,223,372,036,854,775,808 到 +9,223,372,036,854,775,807 之间的值.现在正如您在下面看到的,我创建了一个名为 testLong
的 long
变量,尽管当我插入 9223372036854775807 作为值时,我收到一条错误消息:
I am working with data types at the moment in Java, and if I have understood correctly the type long
accepts a value between the ranges of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. Now as you can see below, I have create a long
variable called testLong
, although when I insert 9223372036854775807 as the value, I get an error stating:
int 类型的字面量 9223372036854775807 超出范围.
The literal 9223372036854775807 of the type int is out of range.
我不知道为什么它把 long
数据类型称为 int
.
I don't know why it is referring to the long
data type as an int
.
有人有什么想法吗?
代码:
char testChar = 01;
byte testByte = -128;
int testInt = -2147483648;
short testShort = -32768;
long testLong = 9223372036854775807;
float testFoat;
double testDouble = 4.940656458412;
boolean testBool = true;
推荐答案
在末尾加一个大写的L
:
long value = 9223372036854775807L;
否则,编译器将尝试将文字解析为 int
,因此会出现错误消息
Otherwise, the compiler will try to parse the literal as an int
, hence the error message
这篇关于int 类型的字面量 xyz 超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:int 类型的字面量 xyz 超出范围


基础教程推荐
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01