DANCE WITH JAVA

开发出高质量的系统

常用链接

统计

积分与排名

好友之家

最新评论

jdk1.5中的新特性 --- 泛型(简版)

另有一个详细版在这里
Jdk1.5中加入了泛型,解决了很多实际的问题,具体内容讲解见候捷的文章:http://jjhou.csdn.net/javatwo-2004-gp-in-jdk15.pdf
下边是一个使用的简单实例
import java.util.ArrayList;
import java.util.HashMap;

public class TestGeneric {
 public static void main(String[] args){
  //need not cast
  ArrayList<String> strList = new ArrayList<String>();
  strList.add("1");
  strList.add("2");
  strList.add("3");
  String str = strList.get(1);
  System.out.println("str="+str);
  
  //autobox
  ArrayList<Integer> iList = new ArrayList<Integer>();
  iList.add(1);
  iList.add(2);
  iList.add(3);
  int num = iList.get(1);
  System.out.println("num="+num);
  
  //double generic
  HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
  map.put(1, 11);
  map.put(2, 22);
  map.put(3, 33);
  int inum = map.get(1);
  System.out.println("inum="+inum);
 }
}

posted on 2006-11-06 18:29 dreamstone 阅读(362) 评论(0)  编辑  收藏 所属分类: jdk相关


只有注册用户登录后才能发表评论。


网站导航: