The Optional class is declared as final in Java. Nevertheless, it contains two methods, flatMap and or with the following signatures:
public <U> Optional<U> flatMap(Function<? super T, ? extends Optional<? extends U>> mapper)
and
public Optional<T> or(Supplier<? extends Optional<? extends T>> supplier)
Optional can never be extended, so what is the point of the parts like ? extends Optional<...> in these signatures? Why not just Optional<...> ?
From answers to a similar question here about the final String class I only understood that the compiler doesn't have to reject such constructs. I agree with that, considering the examples that were given. But my question is rather focused on API design, not on the compiler ability to predict all possible use cases. Why did some ever need to allow for the possibility of, for example, a Supplier that yields instances of some impossible class extending Optional?