day15-11-集合框架(泛型接口)

2020-06-23  本文已影响0人  姗婷

//泛型定义在接口上

interface Inter<T>
{
    void show(T t);
}
//类非泛型,继承泛型接口,在方法中已定义泛型类型
class InterImp1 implements Inter<String>
{
    public void show(String s)
    {
        System.out.println("show:"+s);
    }
}

//类泛型,继承泛型接口
class InterImp<T> implements Inter<T>
{
    public void show(T t)
    {
        System.out.println("show:"+t);
    }
}


class GenericDemo5 
{
    public static void main(String[] args) 
    {
        InterImp1 i = new InterImp1();
        i.show("haha");

        InterImp<Integer> ii = new InterImp<Integer>();
        ii.show(4);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读