【发布时间】:2011-05-17 11:14:49
【问题描述】:
如何用java编写这段代码?
public class ComponentsManager
{
private List<IComponent> list = new ArrayList<IComponent>();
public <U extends IComponent> U GetComponent() {
for (IComponent component : list) {
if(component instanceof U)
{
return component;
}
}
}
}
但我不能对泛型类型执行 instanceof。我该怎么做? 谢谢。
【问题讨论】:
标签: java generics reflection