0

When i do the below code, it ask me for casting the value on right side ?

byte myByteTestValue = Byte.MAX_VALUE + 1;

When i do the below code, it didn't ask me for casting the value on right side ?

int myIntTestValue = Integer.MAX_VALUE + 1;

why this is happening, anyone can explain ?

Ravikiran Reddy Kotapati
  • 2,485
  • 3
  • 22
  • 27

1 Answers1

3

The + 1 is treated as an Integer which is larger than a byte. Cast it and the warning goes away.

byte myByteTestValue = Byte.MAX_VALUE + (byte)1;
Shar1er80
  • 9,001
  • 2
  • 20
  • 29