EXPRESSIONS Conditional Operator ? : 15.25
The process for determining the type of a conditional expression depends on the
kind of conditional expression, as outlined in the following sections.
The following tables summarize the rules above by giving the type of a conditional
expression for all possible types of its second and third operands. bnp(..) means to
apply binary numeric promotion. The form "T | bnp(..)" is used where one operand
is a constant expression of type int and may be representable in type T, where
binary numeric promotion is used if the operand is not representable in type T. The
operand type Object means any reference type other than the null type and the
eight wrapper classes Boolean, Byte, Short, Character, Integer, Long, Float,
Double.
Table 15.25-A. Conditional expression type (Primitive 3rd operand, Part I)
3rd →
byte short char int
2nd ↓
byte byte short bnp(byte,char) byte | bnp(byte,int)
Byte byte short bnp(Byte,char) byte | bnp(Byte,int)
short short short bnp(short,char) short | bnp(short,int)
Short short short bnp(Short,char) short | bnp(Short,int)
char bnp(char,byte) bnp(char,short) char char | bnp(char,int)
Character bnp(Character,byte) bnp(Character,short) char char | bnp(Character,int)
int byte | bnp(int,byte) short | bnp(int,short) char | bnp(int,char) int
Integer bnp(Integer,byte) bnp(Integer,short) bnp(Integer,char) int
long bnp(long,byte) bnp(long,short) bnp(long,char) bnp(long,int)
Long bnp(Long,byte) bnp(Long,short) bnp(Long,char) bnp(Long,int)
float bnp(float,byte) bnp(float,short) bnp(float,char) bnp(float,int)
Float bnp(Float,byte) bnp(Float,short) bnp(Float,char) bnp(Float,int)
double bnp(double,byte) bnp(double,short) bnp(double,char) bnp(double,int)
Double bnp(Double,byte) bnp(Double,short) bnp(Double,char) bnp(Double,int)
boolean lub(Boolean,Byte) lub(Boolean,Short) lub(Boolean,Character) lub(Boolean,Integer)
Boolean lub(Boolean,Byte) lub(Boolean,Short) lub(Boolean,Character) lub(Boolean,Integer)
null lub(null,Byte) lub(null,Short) lub(null,Character) lub(null,Integer)
Object lub(Object,Byte) lub(Object,Short) lub(Object,Character) lub(Object,Integer)
693