When it is not possible to use null object, what is the best practice to replace conditional operator null-checks boilerplate like this:
public String getEmployeeName() {
return employee == null ? null : employee.getName();
}
Is there something like below in Java 8 or any utility library?
public String getEmployeeName() {
return nullable(employee, employee -> employee.getName());
}
private <T, R> R nullable(T nullable, Function<T, R> doIfNotNull) {
return nullable == null ? null : doIfNotNull.apply(nullable);
}