使用类参数我有以下类:爪哇 - 在方法参数
public class Publisher<T> {
private static final Class[] SUPPORTED_CLASSES = new Class[]{T1.class, T2.class};
public Publisher() {
if(Arrays.asList(SUPPORTED_CLASSES).contains(T)) { // error: expression expected!
System.out.println("Class not supported!");
}
}
}
我如何检查是否类参数符合执行?
在上面的例子中,我不能使用类参数T作为参数。
检查此线程https://stackoverflow.com/questions/3403909/get-generic-type-of-class-at-runtime –
为什么你想这个,如果我可能会问? –
@MCEmperor我想检查课程是否受支持,并在必要时记录警告信息 – FazoM