java generic multi-level wild card


Was having a interesting issue on Generic which i thought i was pretty familiar with.

Basically i need to pass a

Map<String, List<SubClass>()>

to a

Map<String, List<SuperClass>()>

I was thinking i could just do

Map<String, List<? extends SuperClass>()>

in the method signature, then i should be fine. But i get compiler error complaining type not compatible.

It turns out that the Map i pass in is actually a

HashMap<String, ArrayList<SubClass>()>

where the ArrayList is not the same type as List.

To fix this, i need to make the signature:

Map<String, ? extends  List<? extends SuperClass>()>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s