Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 1
    this approach defers the type check until the runtime of the program. two consequences: it will be slower at runtime and IDE won't let you know if you by accident try to compare different types.
    – averasko
    Commented Jul 30, 2016 at 1:51
  • 14
    @averasko When you use Object.equals(Object) there is no compile time type check. The Objects.equals(Object, Object) works very much the same as a normal equals, and re inference/checks by IDE, those rules are heuristics that are also supported for Objects.equals(Object, Object) (eg IntelliJ IDEA 2016.2 has the same check for both the normal equals and the one from Objects). Commented Jul 30, 2016 at 8:11
  • 4
    I like this approach. No need to include some ApacheCommons library for things these days. Commented Dec 21, 2016 at 12:59
  • 1
    @SimonBaars This isn't running a function on a null object, this is a static method that you pass two arguments, which can be null, or a reference to an object. Commented Oct 8, 2017 at 15:46
  • 12
    imho this should be the accepted answer. I don't want to reinvent the wheel in every single application I write
    – Neuron
    Commented Jan 9, 2018 at 19:46