String.equals() argument ordering

后端 未结 10 1493
太阳男子
太阳男子 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

    Visit the following link to understand what is meant by Yoda Conditions|Notation

    Its not a "poor coding style" its diferent way of coding.

    Yoda can be usefull to track typos in some languages, i believe the -1 was not deserved to be honest but that is my personal opinion.

    But Yoda can be bad as explained in this lengthy but very interesting article.

    End of the day, there are supporters in favor and against this kinda of notation.

提交回复
热议问题