Imagine that I have a Parent abstract class
public abstract class ParentAbstract {}
And one Child
public abstract class ChildA extends ParentAbstract {}
If I have a method that returns a list of ChildA that looks like this:
private List<ChildA> results() {
return new ArrayList<ChildA>();
}
Why can't I use this method like so? Which calls the above results method
private List<Parent<?>> absctractResults() {
return results();
}
The compiler will throw
java: incompatible types: List<ChildA> cannot be converted to List<Parent<?>>
Why can't the compiler allow that and how to make a method that returns a list of the abstract class that calls other methods returning the child classes?