泛型定義在接口上
/*泛型定義在接口上
*
* */
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);
}
}
浙公網安備 33010602011771號