public class GenericDemo5 {
public static void main(String[] args) {
InterImpl in = new InterImpl();
in.show("Hello World");
InterImpl2<Integer> in2 = new InterImpl2<>();
in2.show(12345);
}
}
//泛型接口。將泛型定義在接口上。
interface Inter<T> {
public void show(T t);
}
class InterImpl implements Inter<String> {
public void show(String str) {
System.out.println("Show: " + str);
}
}
class InterImpl2<Q> implements Inter<Q> {
public void show(Q q) {
System.out.println("Show: " + q);
}
}
打印結果
Show: Hello World
Show: 12345