JAVA编程思想第4版第15章泛型的练习20

来源:互联网 发布:ubuntu 查看jdk 位置 编辑:程序博客网 时间:2024/04/29 00:09
public interface TwoMethodInterface {    void method1();    void method2();}
public class ChildTwoMethodInterface implements TwoMethodInterface {    public void method1(){        System.out.println("ChildTwoMethodInterface:method1");    }    public void method2(){        System.out.println("ChildTwoMethodInterface:method2");    }    public void method3(){        System.out.println("ChildTwoMethodInterface:method3");    }}

public class ChildTwoMethodTest {    public static <T extends TwoMethodInterface> void genericMethod(T t){        t.method1();    }    public static void main(String[] args) {        TwoMethodInterface  childTwoMethodInterface = new ChildTwoMethodInterface();        genericMethod(childTwoMethodInterface);    }}


0 0
原创粉丝点击