简体   繁体   English

如何使用List <? extends Map<String, ?> &gt;

[英]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, ?>> 我不明白我如何调整我的数据以适应List<? extends Map<String, ?>> List<? extends Map<String, ?>> . List<? extends Map<String, ?>>

Thanks. 谢谢。

Okay. 好的。 That <? extends Whatever> <? extends Whatever> <? extends Whatever> is called a bounded wildcard . <? extends Whatever>被称为有界通配符 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 ? ). 它只会匹配你的ArrayList<YourObject>如果YourObject属于一个类实现了Map<String, Something> ,其中Something可以是任何类(那个将匹配无界通配符 ? )。

Your ArrayList is totally fine, since that implements the List interface. 你的ArrayList完全没问题,因为它实现了List接口。 It's your custom MyOwnObject that needs to satisfy the above restrictions. 这是您的自定义MyOwnObject需要满足上述限制。

Read more about wildcards here . 在这里阅读有关通配符的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM