Date finalexamDate = Person.stream()
.map(PersonDetails::getexamDate)
.max(Date::compareTo)
.orElse(null);
The following code produces a
null pointer exception
as this person doesnt have any getexamdate
during this case I wanted to return null
to the finalexamDate
Tried adding Optional.ofNullable
still produces the same error.
How should this be handled ? is there any way to handle along with the same line of code rather than checking one more if condition
?