4

I'm getting annoyed by the smallest things, like when someone does "test".equals(var) instead of var.equals("test").

It not only reduces readability, it just doesn't look right to me. And I don't think there's a difference in performance between the 2.

Comments
  • 1
    Shorter if var can be null
  • 5
    If var is null, it won't throw a null exception and would still make the comparison. This is preferred by many which avoids code like
    var != null && var.equals("test")
  • 2
    Well "test".equals(var) is promoted because if var is null it won't cause a null point exception, and it's cleaner looking than a null check then var.equals but besides that i agree i don't like the way it looks either
  • 1
    @R01101111bert @MAGNUMpt @jckimble I see, I didn't think of that.

    Then again, I think a null-check is nicer than "test".equals(var).
  • 0
    @Larsg310 null check only clutters the statement, and you have to read extra check before getting to the actual check when inspecting code
  • 0
    I personally prefer using actual operators, like ==.
  • 1
    @osmarks while that might work in other languages, it might not work in all e.g. Java.
Add Comment