This is wrong:
byte i = 2;
byte j = 3;
i = i + j;
Solution Manually:
byte i = 2;
byte j = 3;
i = (byte) (i + j);
Shortcut Solution:
byte i = 2;
byte j = 3;
i += j;
What bugs me is why is necessary to cast when we are adding the same data types (byte + byte) and respecting their MAX and MIN value of total storage.
If a byte has a range of MAX and MIN of storage integers from -128 to 127, and 2 + 3 = 5 so
why is it necessary in the example above to cast if they satisfy the range and they both are the same data type?
I also investigated and compound operators by default they cast behind the scenes, but why all this hassle regarding the process of java has behind the scenes to cast like this even in my examples?
Personally not make sense to have inherent this on Java, somebody can explain to me in depth why it is built-in in this way?