Given:
public static <T> void copy(List<? super T> dest, List<? extends T> src)
I have seen this page: Confusion over Java generic method type inference
But I am still confused, dasblinkenlight says that as long as the Object you pass in is consistent then the code should compile.
Does this mean that the first argument type will help determine what is valid for the second?
public class Hello {
public static void main(String[] args){
ArrayList<Animal> dogs = new ArrayList<>();
ArrayList<Marly> marlies = new ArrayList<>();
copy(dogs,marlies);
}
public static <T> void copy(List<? super T> dest, List<? extends T> src{
}
}
class Animal{}
class Dog extends Animal { }
class Beagle extends Dog { }
class Marly extends Beagle{ }
pretty much every which way I have changed around these two lists it compiles, as long as the first is higher in the inheritance hierarchy.
Can someone help explain a little further