Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

list

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.

like image 539
user2250466 Avatar asked Jul 10 '26 22:07

user2250466


1 Answers

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.

like image 174
webuster Avatar answered Jul 13 '26 07:07

webuster