java - 简单的程序,为什么interface可以extends?还有构造函数可以泛型化吗?
巴扎黑
巴扎黑 2017-04-17 17:23:30
[Java讨论组]
interface FactoryI {
  T create();
}

class Foo2 {
  private T x;
  public > Foo2(F factory) {
    x = factory.create();
  }
  // ...
}

class IntegerFactory implements FactoryI {
  public Integer create() {
    return new Integer(0);
  }
}    

class Widget {
  public static class Factory implements FactoryI {
    public Widget create() {
      return new Widget();
    }
  }
}

public class FactoryConstraint {
  public static void main(String[] args) {
    new Foo2(new IntegerFactory());
    new Foo2(new Widget.Factory());
  }
}
巴扎黑
巴扎黑

全部回复(1)
迷茫

接口肯定可以继承的,这个看看资料就可以知道,
至于构造方法,不是构造方法泛型化,就这个类是一个泛型类,怎么说呢,就是自定义一个泛型类就是这样一个格式,也可以看看资料上关于泛型的讲解,还可以看一下List Map等这些泛型类的源码

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号