DEV Community

Discussion on: Java Pitfalls: Unboxing null Booleans

wldomiciano profile image
Wellington Domiciano

Nice! And if you are using Java 9+ and do not want to use third-party library, you can use java.utils.Objects#requireNonNullElse() method:

public boolean checkIfDelivered(Food food) {
  if(food == null) {
    return false;
  } else {
    return Objects.requireNonNullElse(food.wasDelivered(), false);
Enter fullscreen mode Exit fullscreen mode
scottshipp profile image
scottshipp Author

Thanks! That’s a great suggestion!