有没有办法避免以下使用@SuppressWarnings
,并保持相同的功能,而不警告“类型安全:未选中从AbstractDO []转换为E []”:有没有办法在此代码中避免@SuppressWarnings?
public MyClass {
...
private Map<Class<? extends AbstractDO>, AbstractDO[]> map;
...
private void saveConcreteDOs(AbstractDO[] theEntities) {
entityMap.put(theEntities[0].getClass(), theEntities);
}
@SuppressWarnings("unchecked")
protected <E extends AbstractDO> E[] getConcreteDOs(Class<E> theType) {
return (E[]) map.get(theType);
}
...
}
也许提高地图的声明?
以防万一,请忽略NPE和类似的错误 - 代码缩短版,当然 – topchef 2010-09-16 19:27:58
数组和仿制药不拌匀,更好地利用列表,而不是。 – starblue 2010-09-16 19:37:15
谢谢,这是一个选项。 – topchef 2010-09-16 19:42:15