草庐IT

secondCurrentRate

全部标签

java - Double != null 导致 NullPointerException

我有以下代码片段让我感到困扰,其中currentRate和secondCurrentRate是正确定义的Double对象:(currentRate!=null&&secondCurrentRate!=null)?currentRate*secondCurrentRate:null;这应该检查每个Double是否为空,并相应地分配值null。但是,如果secondCurrentRate为null,则会导致NullPointerException。我已将代码段更改为:(currentRate==null|secondCurrentRate==null)?null:currentRate*s