The fundamental issue you are facing is that List<Subclass>
is not a subtype of List<Superclass>
.
The way to solve your problem is to declare the variable using a generic bound:
List<? extends Organism> search;
then this will compile:
search = foods;
The declaration List<? extends Organism>
means "A List of an unknown type that is a subtype of Organism". In code, elements of such a list are known to at least be an Organism, but the exact type is unknown.