-1

There is class called Foo as following:

public class Foo<E> {

    private E val;

    public Foo(E val) {
        this.val = val;
    }

    public <F> Foo<F> map(Function<? super E, ? extends F> f) {
        Foo<F> res = new Foo<F>(f.apply(this.val));
        return res;
    }
}

Then, I call from main:

//Main.java
Foo<Integer> foo1 = new Foo<>(2);
Foo<String> foo2 = foo1.map(a -> a.toString());

My example in Main.java can also work with Function<E, F>. Could you give an example that can work only with Function<? super E, ? extends F>?

vortex
  • 117
  • 7

0 Answers0