Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Expression Type

Status
Not open for further replies.
Oct 3, 2007
15
US
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,
 
String.valueOf(i)

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top