1 package cn.itcast.p4.generic.define.demo; 2 3 public class GenericDefineDemo5 { 4 5 public static void main(String[] args) { 6 // TODO Auto-generated method stub 7 InterImpl in = new InterImpl(); 8 in.show("abc"); 9 10 InterImpl2<Integer> in2 = new InterImpl2<Integer>();//子类对象的时候才知道传入类型 11 in2.show(5); 12 13 14 } 15 16 17 } 18 //泛型接口,将泛型定义在接口上 19 interface Inter<T>{ 20 public void show(T t); 21 } 22 class InterImpl implements Inter<String>{ 23 public void show(String str) { 24 System.out.println("show:"+str); 25 } 26 } 27 class InterImpl2<Q> implements Inter<Q>{//这个类实现的时候还不知道实现的类型是什么 28 //子类对象的时候才知道传入类型 29 public void show(Q q) { 30 System.out.println("show:"+q); 31 } 32 }