I'm able to find out the difference between the Optional.map
& Optional.flatMap
and when to use which method. But what I'm not able to understand what is that the difference between the two method's signatures. From the documentation, I found the below.
public <U> Optional<U> map(Function<? super T,? extends U> mapper)
public <U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper)
Can anyone please explain the difference between Function<? super T,? extends U>
and Function<? super T, Optional<U>>
with some example?