I have declared this:
private ArrayList<? extends Transaction> transactionArray;
I want to add subclasses of Transaction to transactionArray, like so:
public void pushTransaction( Transaction theTrans ) {
transactionArray.add( theTrans );
}
But this is rejected with the message
The method … is not applicable for the arguments…
Do I have to write a separate pushTransaction
method for every subclass of Transaction? Or how can I make this method accept Transaction and its subclasses as valid arguments?
Update: does it make any difference that I have declared Transaction as an abstract class, and am only dealing with its subclasses?