I am trying to do the following in Java using generics:
public class MyType {
public void printBase(Collection<Base> bases) {
for (Base base : bases) {
System.out.println(base.toString());
}
}
public <A extends Base> void myMethod(Collection<A> things) {
// ...
printBases(things); // Error here
// ...
}
}
The error I get is this:
The method printBases(Collection<Base>) in the type MyType is not applicable for the arguments (Collection<A>).
In this case, however, A extends Base
so A is a Base. Shouldn't this method call be legal? If not, how can I solve this problem?