[Java] 纯文本查看 复制代码
//定义一个泛型接口
public interface Inter<E> {
public abstract void show(E e);
}
//接口实现类:确定泛型
public class Imple01 implements Inter<String> {
public void show(String s) {
System.out.println(s);
}
}
//接口实现类,不确定泛型
public class Imple02<E> implements Inter<E>{
public void show(E e) {
System.out.println(e);
}
}
public class Test {
public static void main(String[] args) {
//创建定义泛型的实现类Imple01对象
Imple01 imp1 = new Imple01();
imp1.show("itheima");
//创建不定义泛型的实现类Imple02对象
Imple02<Integer> imp2 = new Imple02<Integer>();
imp2.show(1234);
Imple02<Double> imp3 = new Imple02<Double>();
imp3.show(3.14);
}
}