First, the case number:
u02c09
Second, the case name:
The pains of using conditional operators
Third, the key words:
Conditional operators, three-mesh operators, ternary operators, type conversions
Four, the case scenario description:
The conditional operator has three operands. It is in the form of: BOOLEAN-EXP?EXP1:EXP2. It evaluates the Boolean expression first, and if true, the value of the entire expression is the value of the expression Exp1, and if the Boolean expression evaluates to False, then the value of the entire expression is the EXP2 value.
intk= (2>3) 23:45; Because the Boolean expression 2>3 is False, the value of K is 45.
All of these are about determining the value of the conditional operator, so how is the type of the conditional operator value determined? Look at the following code:
(1)
charx= ' A '; Line1
inti=0; Line2
System.out.println (true?x:0); Line3
System.out.println (true?x:1111111110); Line4
System.out.println (FALSE?I:X); Line5
(2)
/*
* Assume that test is a class that has already been defined
*/
Testt=flase?newobject (): Newtest ();