我有一个名为
现在我有一个类:
Man
的接口。
在这个接口中,我有一个方法getList()
,它返回一个类型为T的列表(取决于实现接口的类)。
我有3个实现了Man
的类: small
,normal
和big
。
每个类都有一个getList()
方法,该方法返回一个small
列表、normal
列表或big
列表。interface Man<T>{
List<T>getList();
}
class small : Man<small>{
List<small> getList(){
return new List<small>();
}
}
class normal : Man<normal>{
List<normal> getList(){
return new List<normal>();
}
}
class big : Man<big>{
List<big> getList(){
return new List<big>();
}
}
现在我有一个类:
Home
,它包含一个参数bed
,该参数是Man
类的实例。
Bed
可以是各种类型:small
、normal
、big
。如何声明bed
的类型参数?class Home{
Man bed<> // what i must insert between '<' and '>'??
}
Home
类上都加上约束,例如:public interface IMan<T> where T : Size{ } public class Home<T> where T : Size { } public abstract class Size { // size objects inherit this } - JG in SD