In Java there's a problem when we are using either byte or short data type.
byte y=19;
byte x=10;
y=y+x; //Compile Error:
System.out.println(y);
Here the output of this program.
error: incompatible types: possible lossy conversion from int to byte
But when we use x+=1, it won't generate any compile error.
byte y=19;
byte x=10;
y+=x; //No Errors !?
System.out.println(y);
Output is 29
Is there a different between x=x+1
and x+=1
using either byte or short data type?