疑问点一:既然泛型在jvm中变成了原始类型,那么他最后是怎么转化为其他类型的呢,比如下面一段代码,getValue()如何知道返回的是Date类型呢
疑问二:为什么下面一段代码不能辣样重写equals的方法?
class Pair<T> {private T value;public T getValue() {return value;}public void setValue(T value) {this.value = value;}
// @Override
// public boolean equals(T t){
// return null;
// }@Overridepublic boolean equals(Object obj) {// TODO Auto-generated method stubreturn super.equals(obj);}
}
疑问三:为什么写Object时,printCollection()方法会爆错
class GernericTest { public static void main(String[] args) throws Exception{ List<Integer> listInteger =new ArrayList<Integer>(); List<String> listString =new ArrayList<String>();printCollection(listInteger);printCollection(listString);}public static void printCollection(Collection<Object> collection){for(Object obj:collection){System.out.println(obj);}}
}