J2SE 1.5 Tiger新特点学习[Java编程]
本文“J2SE 1.5 Tiger新特点学习[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
1、定义一个简单的“泛型”类
package tigers;
public class GenericIdentify {
public static void main(String[] args) {
Generic1<String> gStr = new Generic1<String>();
gStr.set("aaaaaaaaaaaaaaaaa");
Generic1<Integer> gInt = new Generic1<Integer>();
gInt.set(new Integer(1321423));
Generic1<Boolean> gBool = new Generic1<Boolean>();
gBool.set(new Boolean(true));
System.out.println(gStr.get() + "n" +
gInt.get() + "n" +
gBool.get() + "n");
((Generic1)gInt).set("bbbbbbbbbbbbb"); //避开范例查抄
System.out.println(gInt.get());
}
}
class Generic1<A> { //声明泛型
private A a;
public void set(A a) {
this.a = a;
}
public A get() {
return this.a;
}
}
C:tiger>javac -d c:tigercls c:tigersrc*.java
Note: c:tigersrcGenericIdentify.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:tiger>java -classpath c:tigercls tigers.GenericIdentify
aaaaaaaaaaaaaaaaa
1321423
true
bbbbbbbbbbbbb
C:tiger>
以上是“J2SE 1.5 Tiger新特点学习[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |