interface Inter<T>
{
/*<T>*/void show(T t);
}
class InterImpl implements Inter<String>
{
public /*<T>*/void show(/*T*/String t)
{
System.out.println(t);
}
}
interface Inter1<T>
{
void show(T t);
}
class InterImp<T> implements Inter1<T>
{
public void show(T t)
{
System.out.println(t);
}
}
class GenericDemo1
{
public static void main(String[] args)
{
/*InterImpl i=new InterImpl();
i.show("fff");
i.show(5555);*/
InterImp<Integer> i=new InterImp<Integer>();
i.show(5556666);
}
}
1.当方法定义在接口上时,在实现接口的时候已经明确泛型的类型。
|
|--方法定义在接口上,并且接口里的方法上也定义了泛型。(随着方法走)
2.当方法定义在接口上时,在实现接口的时候也没有明确泛型的类型。