6

Found this in my programmer's code. Can I claim temporary insanity when they find his corpse?

Comments
  • 1
    It might make sense.

    The java. lang. Boolean. equals(Object obj) returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object.

    model.getValueAt might return NULL, meaning an implicit NULL check is hidden here.

    And Yeah... Implicit stuff makes one insane as - when you are not aware of it - this line of code can give you a whole lot of migraine, even more when you change it and forget the null implicit check.
  • 0
    What @IntrusionCM said. That's a way to force throwing on a null-object.

    Throwing is considered preferable to just checking for null, because the latter may result in no error being logged in an error scenario, while the application keeps running, but not the way it should.

    Another way in this scenario might be Optional.of() in combination with ifPresent(). Another implicit way of throwing an NPE. The NPE can also be avoided if needed, by using Optional.ofNullable().
Add Comment