JAVA泛型类型的使用举例2

来源:互联网 发布:网络印刷网站 编辑:程序博客网 时间:2024/06/06 01:11

此为说明泛型的另一高级用法:使用通配符达到限制效。

下面的代码经本人测试,望对Java泛型类型不解的人有所帮助。微笑


import java.util.*;/** * This is an another instance for showing the application of the overclass(泛型).  * The aim is to use : * 使用通配符达到限制效果  * @author HAN * * @param <T> the tag of the overclass */@SuppressWarnings("rawtypes")public class OverClassApps2<T> {@SuppressWarnings("unused")public static void main(String[] args){OverClassApps2<? extends List> a=null;  // 使用通配符达到限制效果a=new OverClassApps2<ArrayList>();a=new OverClassApps2<LinkedList>();//a=new OverClassApps2<HashMap>();}}