How come byte is promoted to int, given the fact that data type is byte and there is no unary operator that would convert byte to int. Does arithmetic operator also convert small type to lager one???
Joined: Feb 07, 2005
Binary numeric promotion takes place. That means that a byte, short, or char are going to promoted before the operation. If the other operand is a byte, short, char, or int, the operand will be promoted to an int. If the other operand is a long, the operand will be promoted to a long. Etc.
Binary numeric promotion is performed on the operands of certain operators:
The multiplicative operators *, / and % (�15.17) The addition and subtraction operators for numeric types + and - (�15.18.2) The numerical comparison operators <, <=, >, and >= (�15.20.1) The numerical equality operators == and != (�15.21.1) The integer bitwise operators &, ^, and | (�15.22.1) In certain cases, the conditional operator ? : (�15.25)
The plus and minus also require explicit casting when they are unary operators, thus byte a = 5; byte b = -a; would not compile because the explicit cast is missing.