首页 新闻 会员 周边

List<?> list = new ArrayList<String>();怎么添加元素

0
悬赏园豆:20 [已解决问题] 解决于 2015-05-29 10:29
public static void main(String[] args) {
    List<?> list = new ArrayList<String>();
    list.add(""); // 报错

}


请高手赐教,这个list要怎么添加元素。(或者说List<?>有什么用?) 

感激不尽!

廖龙军的主页 廖龙军 | 初学一级 | 园豆:162
提问于:2015-05-28 21:26
< >
分享
最佳答案
1
收获园豆:20
dudu | 高人七级 |园豆:31003 | 2015-05-28 21:51

明白了,非常感谢!

廖龙军 | 园豆:162 (初学一级) | 2015-05-29 10:27

明白了,非常感谢!

引用原文:

In fact, since you don't know what the ArrayList is supposed to contain, you can't add anything to the ArrayList

廖龙军 | 园豆:162 (初学一级) | 2015-05-29 10:28
其他回答(1)
0

List<?>=泛型集合

请叫我头头哥 | 园豆:9382 (大侠五级) | 2015-05-28 23:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册