软件编程
位置:首页>> 软件编程>> java编程>> java泛型详解

java泛型详解

作者:unbelievableme  发布时间:2023-06-07 23:54:47 

标签:java,泛型

首先请看如下代码:


public class generictype {
public static void main(String str[]) {
 Hashtable h =new Hashtable();
 h.put(1, "String类型");
 int a = (String) h.get(1);
 System.out.println(a);
}
}
//执行结果
String类型
//如果我们将上述由红色标出的String改为int执行后结果如下(更改后编译没有错误):
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at genetictype.generictype.main(generic1.java:10)

来源:http://www.cnblogs.com/kundeg/p/6591621.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com