/*
泛型定義在接口上。
*/
interface Inter<T>
{
void show(T t);
}
/*
//接口的子類知道自己是什麼類型
class ZiInter implements Inter<String>
{
public void show(String s)
{
System.out.println("show:"+s);
}
}
*/
//接口的子類也不知道自己是什麼類型
class ZiInter<T> implements Inter<T>
{
public void show(T t)
{
System.out.println("show:"+t);
}
}
class GenericDemo5
{
public static void main(String[] args)
{
/*
ZiInter zi = new ZiInter();
zi.show("haha");
*/
ZiInter<Integer> zi = new ZiInter<Integer>();
zi.show(5);
}
}