String.equals() argument ordering

后端 未结 10 1516
太阳男子
太阳男子 2020-11-27 06:56

I recently received a downvote for using the following in a recent answer:

String word = ...;
if (\"s\".equals(word) || \"y\".equals(word)

10条回答
  •  佛祖请我去吃肉
    2020-11-27 07:06

    One might argue that you should (unit-)test your code enough to be confident that nulls don't go where they're not supposed to. This should obviate the need for yoda conditions.

提交回复
热议问题