Chinaunix首页 | 论坛 | 博客
  • 博客访问: 243978
  • 博文数量: 164
  • 博客积分: 60
  • 博客等级: 民兵
  • 技术积分: 1129
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-09 21:55
文章分类

全部博文(164)

文章存档

2017年(2)

2015年(67)

2014年(95)

我的朋友

分类: Java

2014-05-15 21:11:29



点击(此处)折叠或打开

  1. //泛型定义在接口上。
  2. interface Inter<T>
  3. {
  4.     void show(T t);
  5. }

  6. /*
  7. class InterImpl implements Inter
  8. {
  9.     public void show(String t)
  10.     {
  11.         System.out.println("show :"+t);
  12.     }
  13. }

  14. */

  15. class InterImpl<T> implements Inter<T>
  16. {
  17.     public void show(T t)
  18.     {
  19.         System.out.println("show :"+t);
  20.     }
  21. }
  22. class GenericDemo5
  23. {
  24.     public static void main(String[] args)
  25.     {

  26.         InterImpl<Integer> i = new InterImpl<Integer>();
  27.         i.show(4);
  28.         //InterImpl i = new InterImpl();
  29.         //i.show("haha");
  30.     }
  31. }

阅读(214) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~