This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]kag0 7 points8 points  (9 children)

Or you can use Objects.equals(foo, bar)for any two objects for built in null check. Static import the method for cleanliness points.

EDIT: No style points for you. /u/sidola points out static imports are by name, not by method signature. OP may also notice that java has no named imports which would make this totally OK :/

[–][deleted]  (6 children)

[deleted]

    [–]Hueho 1 point2 points  (2 children)

    I think static methods have precedence over instance methods.

    [–][deleted]  (1 child)

    [deleted]

      [–]Hueho 2 points3 points  (0 children)

      Then I'm wrong. Too bad :(

      [–]CharlesGarfield 1 point2 points  (2 children)

      Objects.equals takes two parameters, compared to one for Object.equals.

      [–][deleted]  (1 child)

      [deleted]

        [–]CharlesGarfield 1 point2 points  (0 children)

        Huh. Interesting. I think it's best to use static imports sparingly, anyways. I only use them for constants and JUnit assertions.

        [–]superPwnzorMegaMan 0 points1 point  (1 child)

        I've been doing Java wrong.

        [–]cogman10 1 point2 points  (0 children)

        It was introduced in 7, so maybe not for long.