I have a superclass with several subclasses.
public abstract class SuperClass { } public class SubClass1 extends SuperClass { }
I created an ArrayList to contain objects of type SuperClass.
private ArrayList<SuperClass> list = new ArrayList<SuperClass>();
There are several errors that I see in Eclipse.
Firstly, any attempt to add a subclass object has an error:
SubClass1 object; object = new SubClass1(parameters); list.add(object)
Later in the code, when I try to apply one type to another, I get even more problems:
for (SuperClass obj : list){ if (obj instanceof SubClass1){
Not to mention that there are some methods that I call clearly defined in the superclass that look undefined for the type. I am banging my head. I do not know what's the problem.
If you could possibly point me to some possible directions, I would be very obliged. I do not know if I have provided enough information, so please ask any questions that you think might be applicable.
Thanks in advance.
source share