/*泛型定义在接口上
*
* */
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);
}
}
转载于:https://www.cnblogs.com/gongxueliang1989/p/5451388.html