<div class="para" style="font-size:14px; word-wrap:break-word; color:rgb(51,51,51); margin-bottom:15px; text-indent:28px; line-height:24px; zoom:1; font-family:arial,宋体,sans-serif">
泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数。这种参数类型可以用在类、接口和方法的创建中,分别称为<a target="_blank" href="http://baike.baidu.com/view/2104244.htm" rel="nofollow" style="color:rgb(19,110,194); text-decoration:none">泛型类、泛型接口、泛型方法。?<a target="_blank" href="http://baike.baidu.com/view/229611.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">Java语言引入泛型的好处是安全简单。
<div class="para" style="font-size:14px; word-wrap:break-word; color:rgb(51,sans-serif">
在Java SE 1.5之前,没有泛型的<a target="_blank" href="http://baike.baidu.com/view/780206.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">情况的下,通过对类型Object的引用来实现参数的“任意化”,“任意化”带来的缺点是要做显式的<a target="_blank" href="http://baike.baidu.com/view/2886403.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">强制类型转换,而这种转换是要求开发者对<a target="_blank" href="http://baike.baidu.com/view/2245196.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">实际参数类型可以预知的情况下进行的。对于强制类型转换错误的情况,<a target="_blank" href="http://baike.baidu.com/view/487018.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">编译器可能不提示错误,在运行的时候才出现异常,这是一个安全隐患。
<div class="para" style="font-size:14px; word-wrap:break-word; color:rgb(51,sans-serif">
泛型的好处是在编译的时候检查<a target="_blank" href="http://baike.baidu.com/view/1965709.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">类型安全,并且所有的<a target="_blank" href="http://baike.baidu.com/view/965170.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">强制转换都是自动和<a target="_blank" href="http://baike.baidu.com/view/2852863.htm" rel="nofollow" style="color:rgb(19,194); text-decoration:none">隐式的,以提高代码的重用率。
<div class="para" style="font-size:14px; word-wrap:break-word; color:rgb(51,sans-serif">
。习惯上称为“有界类型”。
classType = Class.forName("java.lang.String");
| ??{
?
?
?
??
?
?
?intOb?=??(
?
?
?strOb?=?(