Bra*_*rad 4 java generics inheritance interface subclass
我有一个实现特定接口的通用列表类.
界面中的列表项也实现了相同的界面.
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的泛型类类型有其他限制"?
请告诉我,如果我可以改写这个来帮助解释它.
这有用吗?
public abstract class SearchList<T extends SomeInterface & SearchListItem> extends List<T>
| 归档时间: | 
 | 
| 查看次数: | 1397 次 | 
| 最近记录: |