Originally posted by Cherry Singhal:
Also what do you mean by binary numeric promotion?
BINARY NUMERIC PROMOTION Binary numeric promotion implicitly applies appropriate widening primitive conversions so that a pair of operands have the broadest numeric type of the two, but which is always at least
int. Given
T to be the broadest numeric type of the two operands, the operands are promoted as follows under binary numeric promotion:-
"If
T is broader than
int, both operands are converted to
T, otherwise both operands are converted to
int."
This means that
byte,
short,
char are always converted to at least
int by binary numeric promotion.
Binary numeric promotion applies to the following:-
Operands of arithmetic operators *, /, %, + and -Operands of the relational operators <, <=, > and >=Operands of the numeric equality operators == and !=Operands of the integer bitwise operators &, ^ and | For example,
byte b = 2;
int i = 5;
int j = 6;
b = ++b; // No binary numeric promotion ... Works fine
b = b+i+j; // Error! int found, instead of byte {not constant exp}
[ November 22, 2006: Message edited by: Abdul Rehman ]