我有下面的代碼段試圖瞭解泛型
public static void main(String[] args) {
ArrayList<Integer> iList = new ArrayList();
iList = returList();
for (int i = 0; i < iList.size(); i++) {
System.out.println(iList.get(i));
}
}
public static ArrayList returList() {
ArrayList al = new ArrayList();
al.add("S");
al.add(1);
return al;
}
現在我的查詢是爲什麼該ArrayList正在接受管線原始ArrayList對象創建「的ArrayList ILIST =新的ArrayList();」甚至從方法調用返回均勻的情況。
現在,哪種類型的數據將會在那裏,泛型將暗示什麼?我看不到編譯錯誤,而且這些代碼甚至運行良好。
參見:http://stackoverflow.com/questions/490091/java-generics – Matthias 2012-02-23 11:56:16
@adarshr意味着當你找到它 – 2012-02-23 12:24:51