此为说明泛型的另一高级用法:使用通配符达到限制效。
下面的代码经本人测试,望对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>();
}
}