我已经实现了一个带有协/逆变类型约束的接口,编译器告诉我'Student' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'UserQuery.IMail<T,U>'
从我所见,我满足了这些要求。我究竟做错了什么?
class Person { public Person(){} }
class Student : Person { public Student(){} }
class MatureStudent : Student {public MatureStudent(){}}
interface IMail<in T, out U> where T : new() where U : new() {
void Receive(T t);
U Return();
}
class Mail<Student,MatureStudent> : IMail<Student,MatureStudent> {
public void Receive(Student s) {}
public MatureStudent Return() { return new MatureStudent(); }
}