我有这个 abstract
class
,它接受一个 interface
作为泛型类型:
abstract class A<T: GenericInterface> : T {
...
}
问题是编译器不允许我这样做并且会通过这个错误:
Only classes and interfaces may serve as supertypes
这种情况有什么解决方法吗?
我希望我的类扩展 abstract class A
,传递一个扩展 GenericInterface
的自定义接口,并能够实现该自定义接口方法。
这是我想要实现的原型:
abstract class A<T: GenericInterface> : T {
...
}
interface CustomInterface: GenericInterface {
...
}
class B: A<CustomInterface> {
// Here I want to override CustomInterface funs
}
我知道我总是可以使用这种方法:
class B: A, CustomInterface {
// override CustomInterface funs here
}
但出于代码模式的目的,我想要其他解决方案