| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8367 人关注过本帖
标题:Collection<? extends E> c 什么意思?
只看楼主 加入收藏
koman
Rank: 1
等 级:新手上路
帖 子:71
专家分:0
注 册:2007-9-12
收藏
得分:0 
[bo]以下是引用 [un]Still_Man[/un] 在 2008-2-3 23:08 的发言:[/bo]

Collection是Java中的集合接口,而Collections才是Java中的集合类,LZ可以根据这个查查看,具体也不好说

哦~谢谢!
2008-02-04 02:11
sunboy_2050
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-11-18
收藏
得分:0 
> public class TreeSet<E>
> extends AbstractSet<E>
> implements SortedSet<E>, Cloneable,

Generic class declaration: The "parameter" E is replaced by the programmer when using the class, e.g. TreeSet<String>.

> public boolean addAll(Collection<? extends E> c)

Wildcard generic parameter: It means that the parameter can be any
generic Collection where the parametrized type extends the collection.

So if you have

class Foo { ...

class Fie extends Foo { ...

set = new TreeSet<Foo>();

otherCollection = new ArrayList<Fie>();

you can do a

set.addAll(otherCollection);

because the generic parameter for the second declaration is a class
that extends the parameter class of the first.

http://www.

[ 本帖最后由 sunboy_2050 于 2011-11-18 18:03 编辑 ]
2011-11-18 18:01
李胜利
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2011-3-24
收藏
得分:0 
Collection<? extends E>中?是E的一个子类,例如Collection<? extends List>,此时?可以取ArrayList、LinkedList等
2011-11-19 15:41
快速回复:Collection<? extends E> c 什么意思?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042400 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved