The usage of lower bound in collections context is more or less clear to me (see PECS question). Not so with functional interfaces in Java. E.g. Why Optional.map method has the signature with lower type bound:
<U> Optional<U> map(Function<? super T, ? extends U> mapper);
What is the advantage of using super here and why the code below does not compile?
public static void main(String[] args) {
Function<? super BigDecimal, ? extends Number> mapper = dec -> dec
.divide(BigDecimal.TEN)
.doubleValue();
BigDecimal bigD = BigDecimal.ONE;
//works
Optional.of(bigD).map(mapper);
Number number = BigDecimal.ONE;
// the following does not compile,
// despite Number is super type of BigDecimal
Optional.of(number).map(mapper);
}