泛型Generic

import java.util.ArrayList;
import java.util.Collection;

public class 泛型GenericDemo {
	public static void main(String[] args) {
		//集合中可以存储任意数据类型,实际情况中都是在集合中存储一种数据类型
		//可以通过泛型来指定这种数据类型
		Collection<String> sc = new ArrayList();	
//		指定了泛型之后就不用object来接收了,直接用指定的泛型就可以了
		Generic<String> str = new Generic<String>();
//		String s = str.getByIndex(0);
//		通过索引来获取指定的元素
		
		
	}
}

  

posted @ 2018-07-26 21:56  侯小铁柱  阅读(115)  评论(0)    收藏  举报