我有一个继承抽象类的类,该类继承了另一个抽象类。我可以将最超类定义为泛型就好了,但是在我在最终ListResults类中表达我想要的实际类型之前,我不知道如何将中间类定义为泛型。internal abstract class LowerCommand<T> { public abstract void Execute(); public abstract List<T> ExecuteList();}// currently gives error for `T`internal abstract class HigherCommand : Lowercommand<T> { // ... defines other stuff, nothing to do with // already instantiated methods or T ...}class ListResults : HigherCommand<Results>{ public override void Execute() {...} public override List<Results> ExecuteList() {...}}感谢您的帮助。
1 回答
牛魔王的故事
TA贡献1830条经验 获得超3个赞
您仍然需要在定义上定义泛型类型参数T,HigherCommand以便它可以依次正确定义LowerComand.
internal abstract class LowerCommand<T> {
public abstract void Execute();
public abstract List<T> ExecuteList();
}
// Note that HigherCommand require a declaration of `T`
internal abstract class HigherCommand<T> : Lowercommand<T> {
// ... defines other stuff, nothing to do with
// already instantiated methods or T ...
}
class ListResults : HigherCommand<Results>
{
public override void Execute() {...}
public override List<Results> ExecuteList() {...}
}
- 1 回答
- 0 关注
- 426 浏览
添加回答
举报
0/150
提交
取消