java. ternary operator

If the ternary operator experience can be converted into a digital type: e.g. Integer, Double, etc. type, then it will happen automatically lift integer

Example:

Object o1 = true ? new Integer(1) : new Double(2.0);
System.out.println(o1); // 输出 1.0
Object o2 = false ? new Double(3.0) : new Integer(4);
System.out.println(o2); // 输出 2.0
Published 351 original articles · won praise 2 · Views 9168

Guess you like

Origin blog.csdn.net/qq_45239139/article/details/104185623
Recommended