In the JVM, every stack element has a size of 32 bits. The actual addition works like this:
- The two bytes are pushed on the stack as 32bit values (therefore they are
int
) - The
iadd
instruction is called, which pops two values from the stack and adds them - The resulting integer is pushed on the stack again
This is why you have to cast the resulting value (of type int
) to a byte
again.