Java equals() ordering

后端 未结 6 959
执念已碎
执念已碎 2021-01-12 02:55

If I try to do a .equals() on a null string in java, a null pointer exception will be thrown. I am wondering, if I am trying to compare if a string is equal to

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 03:22

    Nope, it's usually done to avoid NPE. However, I usually prefer to do explicit check for null.

提交回复
热议问题