[英]How to define a generic abstract class that inherits a generic abstract class?
I have a class that inherits an abstract class which inherits another abstract class. 我有一个继承一个抽象类的类,该抽象类又继承了另一个抽象类。 I can define the most-super class as being generic just fine, but I don't know how to define the middle class as being generic before I express the actual type I want in the final
ListResults
class. 我可以将最高级的类定义为泛型,但是在最终
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() {...}
}
Thanks for your help. 谢谢你的帮助。
You still need to define the generic type parameter T
on the definition of HigherCommand
so it can in turn properly define LowerComand
. 您仍然需要在
HigherCommand
的定义上定义通用类型参数T
,以便可以依次正确定义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() {...}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.