これは私が使用しているコードで、インスタンス化時にビルド エラーが発生しています。私の SpecialHandler が T が SpecialEntity として設定された BaseHandler 型であることが表示されない理由がわかりません
static class HandlerFactory
{
public static BaseHandler<BaseEntity> Create(string typeString)
{
throw new NotImplementedException();
}
public static BaseHandler<T> Create<T>(string typeString ) where T : BaseEntity {
if (typeString == "Special")
**return new SpecialHandler();** //THERE'S BUILD ERROR HERE EVEN THOUGH Special Handler is inherits from type BaseHandler<T>
else
return null;
}
}
public class BaseHandler<T> where T : BaseEntity
{
public T GetEntity()
{
throw new NotImplementedException();
}
}
public class SpecialHandler : BaseHandler<SpecialEntity> {}
public class BaseEntity{}
public class SpecialEntity : BaseEntity{}