首页 > 编程语言 > 详细

Java泛型

时间:2014-11-11 16:11:23      阅读:269      评论:0      收藏:0      [点我收藏+]

感觉和c++的模板很类似,这里记录一下基本的认识

 1 public class Test<T> {
 2     private T obj;
 3     public Test(T obj){
 4         this.obj = obj;
 5     }
 6     public T getObj(){
 7         return this.obj;
 8     }
 9     public void setObj(T obj){
10         this.obj = obj;
11     }
12     public void showType(){
13         System.out.println("the type is:" + obj.getClass().getName());
14     }
15     public static void main(String[] args) {
16         Test<String> test1 = new Test<String>("string");
17         test1.showType();
18         Test<Integer> test2 = new Test<Integer>(24);
19         test2.showType();
20     }
21     
22 
23 }

 

Java泛型

原文:http://www.cnblogs.com/luckygxf/p/4089575.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!