Ternary Operator and unexpected NullPointerException

后端 未结 2 512
慢半拍i
慢半拍i 2021-01-18 13:42

I am getting NullPointerException from the below line sometimes.

System.out.println(\"Date::\"+ row != null ? row.getLegMaturityDate() : \"null         


        
2条回答
  •  被撕碎了的回忆
    2021-01-18 14:25

    "Date::" + row is never null, although row sometimes is.

    That is, "Date::"+ row != null is equivalent to ("Date::"+ row) != null which is always true.

提交回复
热议问题