本文介绍了int类型的文字xyz超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Java中的数据类型,如果我已正确理解类型 long 接受范围之间的值:-9,223,372,036,854到+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 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:

我不知道为什么它将 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超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 07:36