首页 > 其他 > 详细

泛型定义在接口上

时间:2016-05-01 23:06:56      阅读:275      评论:0      收藏:0      [点我收藏+]

/*泛型定义在接口上
 *
 * */

package 泛型;


interface Inter<T>{
    void show(T t);
}
//第一种方式
class InterImpl implements Inter<String>{

    public void show(String t) {
        System.out.println("show:"+t);
    }
    
}
//第二种方式
class InterImpl2<T> implements Inter<T>{

    public void show(T t) {
        System.out.println("show:"+t);
        
    }
    
}

public class GenericDemo2 {
    public static void main(String[] args) {
        InterImpl i = new InterImpl();
        i.show("haha");
        
        InterImpl2<Integer> i2 = new InterImpl2<Integer>();
        i2.show(4);
    }
}

泛型定义在接口上

原文:http://www.cnblogs.com/gongxueliang1989/p/5451388.html

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