Why can NOT be added a new Object into a List if with this type is supposed to be able to add any supertype of Apple?
import java.util.List;
import java.util.ArrayList;
class Apple{}
public class Macintosh extends Apple {
public static void main(String[] munch){
List<Apple> a = new ArrayList<Apple>();
basket(a);
}
static void basket(List<? super Apple> list){ list.add(new Object());}
}
If we change argument to List list, of course it works :s
class Animal{}
class Dog extends Animal{}
class Cat extends Animal{}
public class Mixer<A extends Animal>{
public <C extends Cat> Mixer<? super Dog> useMe(A a, C c){
return new Mixer<Animal>();
}
}
Why can we use Mixer in return time if the compiler in the case before didn't know about the Class of the object, now is because of is a class ?¿?