Gracefully avoiding NullPointerException in Java

前端 未结 9 1383
夕颜
夕颜 2020-11-30 04:02

Consider this line:

if (object.getAttribute(\"someAttr\").equals(\"true\")) { // ....

Obviously this line is a potential bug, the attribute

9条回答
  •  借酒劲吻你
    2020-11-30 04:45

    Always aspire for shorter code, given that both are functionaly equivalent. Especially in case like this where readability is not sacrificed.

提交回复
热议问题