user2250466
user2250466

Reputation: 89

How to use List<? extends Map<String, ?>>

I'm trying to use a constructor of a library i'm using. But i need to pass it this object :

 List<? extends Map<String, ?>>

But i have only an object :

 data = ArrayList<MyOwnObject>.

I don't understand how i adapt my data to fit in List<? extends Map<String, ?>>.

Thanks.

Upvotes: 3

Views: 1771

Answers (1)

webuster
webuster

Reputation: 2510

Okay. That <? extends Whatever> is called a bounded wildcard. It will only match your ArrayList<YourObject> if YourObject belongs to a class implements Map<String, Something>, where Something can be any class (that one will match the unbounded wildcard ?).

Your ArrayList is totally fine, since that implements the List interface. It's your custom MyOwnObject that needs to satisfy the above restrictions.

Read more about wildcards here.

Upvotes: 4

Related Questions