4
我有一個實現特定接口的泛型列表類。基於Java中超類和子類的泛型類型的多重限制
界面中的列表項也實現相同的界面。
public abstract class List<T extends SomeInterface> implements SomeInterface
{
protected LinkedList<T> m_list;
...
}
所以現在我想使這個列表保持通用的,但限制的項目實現了SearchListItem界面對象的子類:
public interface SearchListItem
{
public String getName();
}
下面是我對SearchList類到目前爲止:
public abstract class SearchList<T extends SearchListItem> extends List<T>
{
public T get(String name)
{
...
}
...
}
但是,當然,這對投訴類的定義:
Bound mismatch: The type T is not a valid substitute for the bounded parameter <T extends SomeInterface> of the type List<T>
那麼我需要放入類聲明來說「SearchList擴展了List類,並且對包含SomeInterface(在基類)和SearchListItem中的泛型類類型也有其他限制」?
請告訴我,如果我可以用這個詞來幫助解釋它。
完美!我已經實現了它,它聽起來很健康。 – Brad 2010-11-03 09:46:30