In code I created user defined class Myclass and Myclass2 which extends Myclass and then used in ArrayList<? extends Myclass> as a arguments that means now we can pass ArrayList of Myclass and the class which extends Myclass but it is not working it comes up with incompatible types: Myclass cannot be converted to CAP#1 where CAP#1 is a fresh type-variable:CAP#1 extends Myclass from capture of ? extends Myclass
so How we can make such argument that holds object which extends Myclass?
class Myclass{
}
class Myclass2 extends Myclass{
}
public class GenericCheck{
public static void method (ArrayList<? extends Myclass> al){
al.add(new Myclass());
}
public static void main(String args[]){
ArrayList<Myclass> al = new ArrayList();
GenericCheck.method(al);
}
}