为什么会有这种类型转换
資深大佬 : anzu 5
private static Integer getInteger() { return null; } public static void main(String[] args) { boolean condition = false; // error: null pointer exception Integer i = condition ? 1 : getInteger(); if (Objects.equals(i, 1)) { System.out.println("i == 1"); } else { System.out.println("i == null"); } }
为什么是 getInteger() 返回值退化成 int 而不是 1 提升为 Integer ?
大佬有話說 (4)