当注解应用于一个方法时,它似乎过多了。
如何使用注释@SuppressWarning(“未选中”)进行单个强制转换,而不是整个方法?
在本例中,我刚刚检查了强制转换是否安全,因此我继续进行强制转换,但收到了一个恼人的警告。
@Override
public void execDetails()
{
Map<Integer, ResponseList<?>> responseMap =
new HashMap<Integer, ResponseList<?>>();
// ... omitted code ...
ResponseList<?> responseList = responseMap.get(requestId);
Class<?> elementType = responseList.getElementType();
if (elementType == ExecutionDetail.class)
((ResponseList<ExecutionDetail>)responseList).add(new ExecutionDetail());
}
发布于 2011-11-04 21:10:27
您可以为这一行提取一个方法,并对该行/方法进行抑制。
许多工具/ides都有自己的方法,比如将注释放在局部变量上,但我不相信所有的编译器都支持这一点。
https://stackoverflow.com/questions/8009612
复制相似问题