Is CONSTANT.equals(VARIABLE) faster than VARIABLE.equals(CONSTANT)?

后端 未结 7 1722
小蘑菇
小蘑菇 2021-02-07 11:43

I had an interesting conversation with one of my team mate.

Is CONSTANT.equals(VARIABLE) faster than VARIABLE.equals(CONSTANT)in Java?

相关标签:
7条回答
  • 2021-02-07 12:22

    That depends only on the implementation of the equals method. It could be quicker, it could be the slower and it could be the same... Often it is the same. Also it does not depend on the fact that one is a variable and the other a constant but on the content both objects.

    One advantage of Constant.equals(variable) is that you can't have a NullPointerException on the .equals

    0 讨论(0)
提交回复
热议问题