泛型接口的定义与使用

泛型接口的定义与使用

public interfaceInter<T> {  //泛型接口的定义

    public abstract void show(T t);

}

 

public classInterImpl<T> implements Inter<T>{  //泛型接口的实现

 

    @Override

    public void show(T t) {

        // TODO Auto-generated method stub

        System.out.println(t);

    }

   

}

 

public classInterDemo {  //泛型接口的测试

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

 

        Inter<String> i = new InterImpl<String>();

        i.show("hello");

       

        Inter<Integer>i1 = newInterImpl<Integer>();

        i1.show(30);

    }

 

}

运行结果:

hello

30


你可能感兴趣的:(泛型,泛型接口)