[英]Java 11 - Byte.MIN_VALUE & Byte.MAX_VALUE are showing errors in IntelliJ IDEA CE
I'm trying to get the minimum and maximum values of the byte data type printed but the Byte.MIN_VALUE
& the Byte.MAX_VALUE
are highlighted in red in the IDE.我正在尝试打印字节数据类型的最小值和最大值,但
Byte.MIN_VALUE
和Byte.MAX_VALUE
中以红色突出显示。 I'm using IntelliJ IDEA community edition.我正在使用 IntelliJ IDEA 社区版。 Would someone be able to help, please?
请问有人可以帮忙吗? Thanks in advance.
提前致谢。
public class Byte {
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
You are giving Class Name as Byte so its refer the same class name.您将 Class 名称作为字节提供,因此它引用相同的 class 名称。 Change the class name to some other name.
将 class 名称更改为其他名称。
public class Test {
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
You have declared your own Byte
class.你已经声明了你自己的
Byte
class。 (Bad idea...) (馊主意...)
Within your Byte
class, references to Byte
are referring to >>this<< class, not to java.lang.Byte
.在您的
Byte
class 中,对Byte
的引用指的是 >>this<< class,而不是java.lang.Byte
。 But your Byte
class does not declare MIN_VALUE
or MAX_VALUE
.但是您的
Byte
class 没有声明MIN_VALUE
或MAX_VALUE
。 Hence the compilation error... indicated by the red highlighting.因此编译错误......由红色突出显示。
Solutions:解决方案:
Change the name of your class.更改 class 的名称。 It is a bad idea to use a name for your class that is the same as the name of a standard class.
为 class 使用与标准 class 的名称相同的名称是个坏主意。 If leads to various confusing compilation errors....
如果导致各种令人困惑的编译错误......
Use the qualified name for the standard class;使用标准 class 的限定名称; ie change
即改变
byte myMinByteValue = Byte.MIN_VALUE;
to至
byte myMinByteValue = java.lang.Byte.MIN_VALUE;
"Byte" is a reverse word or keyword of java. “字节”是 java 的反向字或关键字。 You can't use any reserve word(keyword) as a class name or variable name.
您不能使用任何保留字(关键字)作为 class 名称或变量名称。 Change your class name.
更改您的 class 名称。
class Test{
public static void main(String[] args){
byte myMinByteValue = Byte.MIN_VALUE;
byte myMaxByteValue = Byte.MIN_VALUE;
System.out.println("Byte Minimum Value = " + myMinByteValue);
System.out.println("Byte Maximum Value = " + myMaxByteValue);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.