/*
泛型定义在接口上。
*/
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);
}
}
day15/GenericDemo5.java
最新推荐文章于 2025-03-14 23:53:25 发布
