关于泛型的一些文章
来源:互联网 发布:手机淘宝源码 编辑:程序博客网 时间:2024/06/03 23:39
泛型的使用原则: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
- 关于泛型的一些文章
- 一些关于数据库的文章
- 一些关于VC的文章
- 关于CoreDump的一些文章
- 一些关于Launcher的文章
- 关于C++的一些文章
- 关于QT的一些文章
- 关于mockito的一些文章
- 关于autohotkey的一些文章
- 一些关于Linux的有意思的文章
- 收藏的关于JS的一些文章
- 发现的一些关于python的文章
- 关于编程的一些好的文章
- 一些关于水晶报表的文章
- 一些关于计算机围棋的文章
- 关于Tomcat配置的一些文章地址
- 关于WinDbg的一些文章收藏
- 【转】关于测试方面的一些文章
- javascript 拼接字符串
- 关于配置好了openCV后,新建第二个project可能出现的Link问题
- 数据结构绪论
- (转)视频图像编解码技术:JPEG编解码文件结构分析
- Android 如何直播RTMP流
- 关于泛型的一些文章
- Android SDK自定义更新
- 【16】GridView——网格视图
- 《Effective C++》学习笔记——条款38
- hadoop2.x源码编译
- flume agent arvo传数据
- angular自定义组件popbox练习日志(一)
- BZOJ-3670 动物园 KMP+奇怪的东西
- libgdx [Actor]