2
我写一个工厂类,看起来像这样:检查一个类型参数是一个特定的接口
public class RepositoryFactory<T> {
public T getRepository(){
if(T is IQuestionRepository){ // This is where I am not sure
return new QuestionRepository();
}
if(T is IAnswerRepository){ // This is where I am not sure
return new AnswerRepository();
}
}
}
,但我怎么能检查T
是一种类型的指定interface
?
你不能。将'Class'实例传递给'getRepository()'。 –