java 泛型多重限制,java中基于超类和子类的泛型类型的多重限制

I have a generic list class that implements a particular interface.

The list items in the interface also implement the same interface.

public abstract class List implements SomeInterface

{

protected LinkedList m_list;

...

}

So now I want to make a subclass of this list that stays generic but limits the items to objects that implement the SearchListItem interface:

public interface SearchListItem

{

public String getName();

}

Here's what I have for the SearchList class so far:

public abstract class SearchList extends List

{

public T get(String name)

{

...

}

...

}

But of course this complains on the definition of the class:

Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type List

So what do I need to put into the class declaration to say "SearchList extends the List class and has additional restrictions on the generic class type that includes both SomeInterface (in the base class) and SearchListItem as well"?

Please tell me if I can reword this to help explain it.

解决方案

Does this work?

public abstract class SearchList extends List

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值