用Java继承Collection泛型,问题

时间:2018-10-21 22:18:06

标签: java

在Java中使用泛型时遇到编译问题

  public class Subject<T>{
  private  long id;
    private T data;
//..
    public T getData() {

        return this.data;

    }

}

    import com.res.emorobots.observer.OrdersIterableObserver;

public class OrdersIterableSubject<T1 extends Collection<OrdersIterableObserver<T2>> ,T2 extends Collection<Order>> extends Subject<Collection<OrdersIterableObserver<T2>>>{

    private  long id;
    private T2 data;
   protected T1  observers;

    public T2 getData() {

        return  this.data;

    }

}

错误: 这行有多个标记     -返回类型与Subject >>。getData()不兼容     -覆盖      com.res.emorobots.subject.Subject >>。getData

有什么想法吗?谢谢您。

1 个答案:

答案 0 :(得分:0)

select l.id, cl.Category_ID from listings as l inner join CategoryListings as cl on l.id=cl.Listing_ID inner join Categories as c on c.ID = cl.Category_ID where c.id in (select id from Categories where id =1 or id=3) 扩展了OrdersIterableSubject,因此其Subject<Collection<OrdersIterableObserver<T2>>>方法必须返回:

getData

(或子类型)