Its ternary operator
also referred to as the conditional operator, have a look reference
like Object bar = foo.isSelected() ? getSelected(foo) : getSelected(baz);
eg. operand1 ? operand2 : operand3
- if operand1 is true, operand2 is returned, else operand3 is returned
- operand1 must be a boolean type
- operand1 can be an expression that evaluates to a boolean type
- operand1 and operand2 must be promotable numeric types or castable object references, or null
- if one of operand2 or operand3 is a byte and the other a short, the type of the returned value will be a short
- if one of operand2 or operand3 is a byte, short or char and the other is a constant int value which will fit within the other operands
range, the type of the returned value will be the type of the other
operand
- otherwise, normal binary numeric promotion applies
- if one of operand2 or operand3 is a null, the type of the return will be the type of the other operand
- if both operand2 and operand3 are different types, one of them must be compatible (castable) to the other type
reference