Recently I've been studying Generic Types and a little bit of Wildcards. I'm going to illustrate the problem with an example code:
ArrayList<SuperClass> arraySuper = new ArrayList<>();
ArrayList<SubClass> arraySub = new ArrayList<>();
arraySuper.add(new SuperClass());
arraySuper.add(new SubClass());
Where SuperClass obviously is the super class of Subclass. In this example SuperClass in the diamond operator means "SuperClass or its subclasses". This is reasonable. But here:
static void doSomething(ArrayList<SuperClass> idk) {}
with
doSomething(arraySuper);
doSomething(arraySub); // Compile Error
SuperClass means "only SuperClass and not its subclasses."
Why is there this difference? Thanks for all answers.