ITPub博客

首页 > > > java泛型类继承问题?

java泛型类继承问题?

作者:germo 时间:2019-09-29 13:41:12 0 删除 编辑

//GeoResult 类

  public class GeoResult<T> implements Serializable {

    private static final long serialVersionUID = 1637452570977581370L;  

    private final T content;    private final Distance distance;

    public GeoResult(T content, Distance distance) {

      Assert.notNull(content, "Content must not be null!");

      Assert.notNull(distance, "Distance must not be null!"); 

      this.content = content;       

      this.distance = distance;

    }

  }

 

//通过继承扩展GeoResult类

//通过继承扩展GeoResult类

public class GeoExtendResult extends GeoResult implements Serializable{

public GeoExtendResult(T content, Distance distance) {

super(content, distance);

}

}

//这是正确的

List>> geoResultList =  radiusGeo.getContent();

//报类型不匹配

List>> geoResultList =  radiusGeo.getContent();

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1868/viewspace-3169788/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-17

  • 博文量
    209
  • 访问量
    8232