0

while I was innocently performing some binary operations on bytes in Java, I encountered the following:

enter image description here

Apparently, byte & byte = int in Java. Same fate for chars.

Longs and booleans, on the other hand, don't suffer from this.

I expected to be able to keep working with bytes without casting.

It seems hackish to have to cast. Is there no more elegant approach?

Why don't I get a byte or char back? Does this have something to do with 32 bit registers and machine code?

Frido Emans
  • 5,120
  • 2
  • 27
  • 42

0 Answers0