I have two classes like this
public class Wire<E extends Electricity> implements Connection<E> {
private ArrayList<Inlet<E>> outlets = new ArrayList<Inlet<E>>();
public void outputToAll() {
for (Inlet<E> inlet : outlets){
inlet.addToStore(new Electricity(amountPer));
}
}
}
and
public abstract class Inlet<E> {
private E store;
public void addToStore(E inputObj){
this.store.add(inputObj);
}
}
Inlet doesn't have any errors, but Wire gives me the error that
The method addToStore(E) in the type Inlet is not applicable for the arguments (Electricity)
However, since in outputToAll E must extend electricity, so Inlet is at least Inlet, why does passing an Electricity object to addToStore not work?
And if the compiler isn't smart enough to know that this will work, what is a good workaround?