Unboxing Null-Object to primitive type results in NullPointerException, fine?

后端 未结 4 1665
Happy的楠姐
Happy的楠姐 2020-12-03 09:29

This snippet throws an NullPointerException due to the fact that its unboxed to a primitive type and Long.longValue() is called, right?

Tha

4条回答
  •  时光取名叫无心
    2020-12-03 10:13

    Since Java 8 SE there is also Optional.ofNullable

    long value = Optional.ofNullable(obj.getProperty(propertyModel.getName())).orElse(0L)));
    

提交回复
热议问题