I have:
protected Map<String, ? extends Transaction> transactions = new HashMap<String, ?>();
However, I get a compilation error:
Type mismatch: cannot convert from HashMap<String,?> to Map<String,? extends Transaction>
I've tried some variations, including:
protected Map<String, ? extends Transaction> transactions = new HashMap<String, ? extends Transaction>();
All yield the same compilation error.
My goal is to have an instance of Report
abstract class
(extended by many different kinds of reports), accept multiple subclassess of the abstract class
Transaction
.
The types going into a single instance of an extended Report
will all be the same type, for example TRRReport extends Report
will need to accept TRRTransaction extends Transaction
into it's HashMap
, however TDDReport extends Report
will need to accept TDDTransaction extends Transaction
into it's HashMap
.
How can I use a HashMap
and Generics
in this situation?