------- <a href="http://www.itheima.com" target="blank">android培訓</a>、<a href="http://www.itheima.com" target="blank">java培訓</a>、期待與您交流! ----------
package addbase;
import java.util.*;
public class 泛型的應用 {
public static void main(String[] args) {
/*
ArrayList collection=new ArrayList();
collection.add(1);
collection.add(1l);
collection.add("abg");
int i=(Integer)collection.get(1);
如果強制轉換Integer結果就會出錯:長不能轉換爲java . lang . integer
想改collection課一按快捷鍵atl+shift+r改變,下面的就會跟這改變。
*/
ArrayList<String> collection1=new ArrayList<String>();
collection1.add("abg");
String str=collection1.get(1);//定義了泛型,不用再類型轉換了。
}
}
------- <a href="http://www.itheima.com" target="blank">android培訓</a>、<a href="http://www.itheima.com" target="blank">java培訓</a>、期待與您交流! ----------