I have a superclass with a couple of 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>();
The errors I'm seeing in Eclipse are several in number.
First, any attempt to add an object of a subclass has an error:
SubClass1 object;
object = new SubClass1(parameters);
list.add(object) //I get error: The method add(SuperClass) in the type
//ArrayList<SuperClass> is not applicable for the arguments
//(SubClass1)
Later on in the code, when I try to cast one type to another, I get even more problems:
for (SuperClass obj : list){
if (obj instanceof SubClass1){ //This gets an error like this:
.... //Incompatible conditional operand types
} // SuperClass and SubClass1
Not to mention that there are some methods that I'm calling that are clearly defined in the superclass that come up as undefined for type. I'm banging my head here. I have absolutely no idea what the problem could be.
If you folks could maybe point me in some possible directions, I'd be much obliged. I don't know if I've even supplied enough information, so please ask any questions that you think might be applicable.
Thanks in advance.
ArrayListthat you have declared.botand follow the advice he gave.. He has pointed out the most proabable reason.. :)