I have a class with an inner class that I override. That seems to be working fine.
class Car {
public static class CarItems
{
public void doStuff(){ ... }
}
}
class Honda extends Car {
public static class CarItems extends Car.CarItems
{
@Override
public void doStuff(){ ... }
}
}
Problem
That Car class is inside another class that I'm also overriding:
class Dealership {
//
// #1: Here's a list of stuff, which includes car items
// as defined in parent class
//
protected List<CarAndStuff> carsAndStuff;
public static class CarsAndStuff {
private List<CarItems> carItems;
private String name;
// ...
//
// #2: This only returns the items from the rest of the
// clutter in this class
//
public List<CarItems> getCarsItems() { return carsItems; }
}
// As defined above
public static class CarItems { ... }
}
class HondaDealership extends Dealership {
//
// #3: This sub-class only cares about the items
//
protected List<CarItems> carItems;
public void extractItemsFromParent() {
List<CarItems> _items = new ArrayList<CarItems>();
for(CarsAndStuff stuff : carsAndStuff) {
//
// #4: So I try to extract the items, but using my
// overriden method. ERROR!
//
carItems.addAll(carsAndStuff.getCarItems());
}
this.carItems = carItems;
}
// As defined above
public static class CarItems extends Car.CarItems { ... }
}
Hopefully that's not too much code to follow, and it's all pretty straight forward... The error I'm getting is that on #4
Java is trying to cast from Car.CarItems up to Honda.CarItems. It says:
The method addAll(Collection<? extends Honda.CarItems>)
in the type List<Honda.CarItems>
is not applicable for the arguments (List<Car.CarItems>)
If Honda.CarItems IS-A Car.CarItems, why won't it let me add a List to a List ??