0

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?

Christos
  • 53,228
  • 8
  • 76
  • 108
  • 1
    @Christos, I have checked the link that you have shared but that doesn't answer my question. – user7704710 Mar 05 '22 at 07:04
  • Ignoring generics, in `map`, the mapping function returns an object of type `U` whereas in `flatMap`, it returns an `Optional`. – Thiyagu Mar 05 '22 at 07:17

0 Answers0