泛型在接口中的使用

主方法

package cn.dali2.code05;
/*接口使用泛型:
* 当接口使用泛型,我们创建实现类的时候,可以直接确定数据类型,也可以实现类继续使用泛型*/

public class Demo01 {
    public static void main(String[] args) {
        Interface01impl in1 = new Interface01impl();
        Interface02impl in2 = new Interface02impl();
        in1.f1(123);
        in2.f1("456");

    }
}

接口

package cn.dali2.code05;

public  interface Interface01 {
    public  abstract void f1(M m);
}

实现类1:

package cn.dali2.code05;

import cn.dali.code20.Interface;

public class Interface01impl implements Interface01{

    @Override
    public void f1(M m) {
        System.out.println(m);
    }
}

实现类2:

package cn.dali2.code05;

public class Interface02impl implements Interface01 {


    @Override
    public void f1(String s) {
        System.out.println(s);
    }
}

你可能感兴趣的:(JAVA)