package cn.itcast.day17.genericInterface;
/*
 * 泛型接口
 */
public interface Inter<T> {
    public abstract void show(T t);
}

 

package cn.itcast.day17.genericInterface;

//实现泛型接口,分为两种情况:
//第一种情况:子类清楚的知道 泛型参数的类型
//第二种情况:子类不知道是什么类型


//第一种情况
/*public class InterImpl implements Inter<String>{
    @Override
    public void show(String t) {
        System.out.println(t);
    }
}*/



//第二种情况
public class InterImpl<T> implements Inter<T>{
    @Override
    public void show(T t) {
        System.out.println(t);
    }
}

 

package cn.itcast.day17.genericInterface;
/*
 * 泛型接口测试 
 */
public class InterGenericTest {

    public static void main(String[] args) {
        //第一种情况测试
//        Inter<String> i=new InterImpl();
//        i.show("123");
        
        //第二种情况测试
        Inter<String> ii=new InterImpl<String>();
        ii.show("java");
    }

}

相关文章:

  • 2021-07-02
  • 2022-12-23
  • 2022-02-27
  • 2018-06-28
  • 2021-11-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-06-11
  • 2021-10-05
相关资源
相似解决方案