I am seeing inconsistent behavior when using a simple assignment operation.
class TestInt {
public static void main(String args[]) {
byte a = 1, b = 1;
b = b + a;
}
}
causes TestInt.java:4: error: incompatible types: possible lossy conversion from int to byte b = b + a; ^ 1 error
whereas this compiles and works fine
class TestInt {
public static void main(String args[]) {
byte a = 1, b = 1;
b += a;
}
}
I do understand why the first piece of code may fail, I just cant figure out why there is a difference between the 2, coming from the C programming world.