This is about a sum of two ints after a cast to bytes in both operands. I'm just trying to understand why the following output works perfectly in Java:
byte b1 = (byte)128 + (byte)18; // ok
System.out.println( b1 );
and the latter fails at compile-time:
byte b2 = (byte)110 + (byte)18; // compile-time error
System.out.println( b2 );
They are identical, except from the int values used as operands. In both cases the result is out of range, but only the second snippet will throw compile-time error (altought its result is less than the the previous one). Just why is this happening?