java中三目运算符踩过的坑

这是一个什么样的坑?

直接上代码:

1
2
//H付款方式
Integer hPaymentWayId = fullfillDTOShip != null ? fullfillDTOShip.getHPaymentWayId() : 0;

看似正常的代码在遇到fullfillDTOShip.getHPaymentWayId()为null时会报NPE错误,为什么会这样呢?

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×