关于泛型的一些文章

泛型的使用原则:Generic methods allow type parameters to be used to express dependencies among the types of one or more arguments to a method and/or its return type. If there isn't such a dependency, a generic method should not be used.

关于<? extends T>和<? super T>的使用原则:In general, if you have an API that only uses a type parameter T as an argument, its uses should take advantage of lower bounded wildcards (super T). Conversely, if the API only returns T, you'll give your clients more flexibility by using upper bounded wildcards (extends T).

if you have an API that only uses a type parameter T as an argument, its uses should take advantage of lower bounded wildcards (super T).


Conversely, if the API only returns T, you'll give your clients more flexibility by using upper bounded wildcards (extends T).:

这种情况就好像,假如T是个接口,你传入的数据是实现了这个接口的类,在方法中做完处理后,作为返回值再返回去。因为返回值的类型是T,所以和传数据同样类型的数据做为返回值没有问题。


官方教程:

http://docs.oracle.com/javase/tutorial/java/generics/index.html

日本教程(非常详细,把官方举的例子的原理都说明白了):

http://www.ne.jp/asahi/hishidama/home/tech/java/generics.html#Generic_型引数

国内教程:

http://www.cnblogs.com/mengdd/archive/2013/01/21/2869778.html

http://www.cnblogs.com/lwbqqyumidi/p/3837629.html

http://www.cnblogs.com/iyangyuan/archive/2013/04/09/3011274.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值