I can’t find any example where wildcards can’t be replaced by a generic.
For example:
public void dummy(List<? extends MyObject> list);
is equivalent to
public <T> void dummy(List<T extends MyObject> list);
or
public <T> List<? extends T> dummy2(List<? extends T> list);
is equivalent to
public <T, U> List<U extends T> dummy(List<U extends T> list);
So I don’t undertand why wildcard was created as generics is already doing the job. Any ideas or comments?
Nope, it is not always replaceable.
is not equivalent to
because you don’t know the
Twhen callingfoo()(and you cannot know whatList<T>willfoo()return. The same thing happens in your second example, too.The demonstration of using wildcards can be found in this (my) answer.