Avoid null unboxing surprises
Assigning a null wrapper such as Integer to an int triggers a NullPointerException during unboxing. Validate the wrapper first or use a primitive/default value when null is not meaningful.
Clear note on java / null. "Avoid null unboxing surprises" is the kind of detail that is easy to overlook.
Clear note on java / null. "Avoid null unboxing surprises" is the kind of detail that is easy to overlook.
"Avoid null unboxing surprises" is a useful thing to know about with java / null. Thanks for sharing it.
The same NPE occurs in a ternary that mixes a wrapper and a primitive, such as
cond ? nullInteger : 0, because the result type is unboxed toint. Got a different fix? Post it in the comments.Appreciate the write-up on "Avoid null unboxing surprises". Useful for anyone using java / null.
Clear note on java / null. "Avoid null unboxing surprises" is the kind of detail that is easy to overlook.
Clear note on java / null. "Avoid null unboxing surprises" is the kind of detail that is easy to overlook.
"Avoid null unboxing surprises" is a useful thing to know about with java / null. Thanks for sharing it.
Good to see "Avoid null unboxing surprises" written down. Handy reference for anyone working with java / null.