[英]Why is class constraint not detected for generic class using an inherited type?
[英]Generic class definition with both generic type constraint and inherited type?
我想知道是否可以同时拥有泛型类型约束和继承类型?
我无法为自己弄清楚语法,也无法想到我可以查看的可能示例。
代码示例:
public class Test<T> where T : ITest, new() : IBaseTest { }
是否有可能实现这样的 class 定义?
public class Test<T>: IBaseTest where T: ITest, new() { }
您的 class 将实现接口IBaseTest
,并将泛型参数T
限制为实现接口ITest
并具有默认(无参数)构造函数的类型。
这是你的意思吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.