TigerFan987
MIS
If I have the code segment:
System.out.print(false ? i : x);
and i is an int and x is a char, shouldn't the type of this conditional expression be char. The Java Language Specification says "If one of the operands is of type T where T is byte, short, or char, and the other operand is a constant expression of type int whose value is representable in type T, then the type of the conditional expression is T." When this code executes it produces the int value for the char x. why? how can I avoid this?
Thanks,
System.out.print(false ? i : x);
and i is an int and x is a char, shouldn't the type of this conditional expression be char. The Java Language Specification says "If one of the operands is of type T where T is byte, short, or char, and the other operand is a constant expression of type int whose value is representable in type T, then the type of the conditional expression is T." When this code executes it produces the int value for the char x. why? how can I avoid this?
Thanks,