Issue
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. I'm using IntelliJ IDEA community edition. 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);
}
}
Solution
You have declared your own Byte
class. (Bad idea ...)
Within your Byte
class, references to Byte
are referring to >>this<< class, not to java.lang.Byte
. But your Byte
class does not declare MIN_VALUE
or MAX_VALUE
. Hence the compilation error ... indicated by the red highlighting.
Solutions:
Change the name of your class. It is a bad idea to use a name for your class that is the same as the name of a standard class. If leads to various confusing compilation errors ....
Use the qualified name for the standard class; i.e. change
byte myMinByteValue = Byte.MIN_VALUE;
to
byte myMinByteValue = java.lang.Byte.MIN_VALUE;
Answered By - Stephen C
Answer Checked By - Willingham (JavaFixing Volunteer)