我有以下几点:
// This part is fine
abstract class Attack {}
abstract class Unit<A> where A : Attack {}
class InstantAttack : Attack {}
class Infantry : Unit<InstantAttack> {}
// I'm lost here, on this part's syntax:
abstract class Controller<U> where U : Unit {}
// I want the above class to take any kind of Unit, but Unit is a generic class!
以上不适用于Controller
,因为where U : Unit
不正确,因为Unit
需要通用参数(如Unit<InstantAttack>
)。我试过了:
abstract class Controller<U<A>> where U<A> : Unit<A> {}
这当然没有用。这样做的正确语法是什么?