如何定义一个继承泛型抽象类的泛型抽象类?

我有一个继承抽象类的类,该类继承了另一个抽象类。我可以将最超类定义为泛型就好了,但是在我在最终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() {...}

}

感谢您的帮助。


慕码人8056858
浏览 427回答 1
1回答

牛魔王的故事

您仍然需要在定义上定义泛型类型参数T,HigherCommand以便它可以依次正确定义LowerComand.internal abstract class LowerCommand<T> {&nbsp; &nbsp; public abstract void Execute();&nbsp; &nbsp; public abstract List<T> ExecuteList();}// Note that HigherCommand require a declaration of `T`internal abstract class HigherCommand<T> : Lowercommand<T> {&nbsp; &nbsp; // ... defines other stuff, nothing to do with&nbsp; &nbsp; //&nbsp; &nbsp; &nbsp;already instantiated methods or T ...}class ListResults : HigherCommand<Results>{&nbsp; &nbsp; public override void Execute() {...}&nbsp; &nbsp; public override List<Results> ExecuteList() {...}}
打开App,查看更多内容
随时随地看视频慕课网APP