Possible Duplicate:
Difference between these two conditions?
I am doing some code cleanup and NetBeans made a suggestion to change
if(!billAddress1.equals(""))
to if (!"".equals(billAddress1))
.
What is the difference between the two, and the advantages of using the suggested version over the readability of the original version?
billAddress1.equals("")
will cause a NullPointerException if billAddress1
is null
, "".equals(billAddress1)
wont.
// Could cause a NullPointerException if billAddress1 is null
if(!billAddress1.equals(""))
// Will not cause a NullPointerException if billAddress1 is null
if (!"".equals(billAddress1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With