Booleans, conditional operators and autoboxing
问题 Why does this throw NullPointerException public static void main(String[] args) throws Exception { Boolean b = true ? returnsNull() : false; // NPE on this line. System.out.println(b); } public static Boolean returnsNull() { return null; } while this doesn\'t public static void main(String[] args) throws Exception { Boolean b = true ? null : false; System.out.println(b); // null } ? The solution is by the way to replace false by Boolean.FALSE to avoid null being unboxed to boolean --which isn