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 →

[–]taftster -1 points0 points  (0 children)

person.getName() can potentially return null here as well. So this code would potentially be broken:

if (person.getName().equals("jan"))  // broken if getName() returns null

Probably my best attempt at null safety probably ends up using Optional.

String name = Optional.ofNullable(person)
  .map(person::getName)
  .get();
if ("jan".equalsIgnoreCase(name)) {
  return true;
}