package cn.itcast_06;
public class InterDemo {
public static void main(String[] args) {
// 第一种情况的测试
// Inter<String> i = new InterImpl();
// i.show("hello");
// 第二种情况测试
Inter<String> i = new InterImpl<String>();
i.show("hello");
Inter<Integer> ii = new InterImpl<Integer>();
ii.show(100);
}
}
package cn.itcast_06;
//实现类在实现接口的时候
//第一种情况:已经知道该是什么类型的了
//public class InterImpl implements Inter<String> {
// public void show(String t) {
// System.out.println(t);
// }
// }
//第二种情况:还不知道是什么类型的
public class InterImpl<T> implements Inter<T> {
public void show(T t) {
System.out.println(t);
}
}
package cn.itcast_06;
/*
* 泛型接口:把泛型定义在接口上
*/
public interface Inter<T> {
public abstract void show(T t);
}