Java: NullPointerException when assigned to null Boolean
When I tried to assign a null Boolean as shown below, I have a NullPointerException.
String strA = "something neither true nor false";
Boolean a = "true".equals(strA) ? true : "false".equals(strA) ? false : null;
I don't know why this happens when other cases like below work.
Boolean a = null;
Boolean a = "true".equals(strA) ? true : null;
+3
source to share