Ternary Operator and unexpected NullPointerException

后端 未结 2 519
慢半拍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:27

    It's a matter of operator precedence. Christoffer Hammarström has the executive summary. See this page http://bmanolov.free.fr/javaoperators.php for more detail.

提交回复
热议问题