【发布时间】:2013-12-17 04:51:59
【问题描述】:
我正在编写一个如下所示的工厂类:
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()。