Imagine this:
class ConcreteClass extends AbstractClass
public class Main {
public void doVector(Vector<AbstractClass> vector) {
for (AbstractClass ob : vector) {
// do Something
}
}
public Main() {
}
public static void main(
String[] args) {
Main main = new Main();
Vector<ConcreteClass> vector = new Vector();
vector.add(new ConcreteClass());
main.doVector(vector);
}
}
This won't compile because vector is Vector<ConcreteClass> not Vector<AbstractClass>
even though ConcreteClass is a subclass of AbstractClass
I can get past this by casting vector to a simple untyped Vector,
although the compiler b!tches about unchecked conversions.
Alternatively I could declare my vectors as Vector<AbstractClass>
but in my application I actually have multiple different Concrete classes so that doesn't help.
Is there another solution that I'm missing?