FindBugs检测到以下代码的SIC_INNER_SHOULD_BE_STATIC_ANON警告。除了忽略SuppressFBWarnings中的警告之外,我如何避免SIC_INNER_SHOULD_BE_STATIC_ANON?
Class MyClass $ 1 may be able to be refactored into a named static inner class.
Local variable name reference
public class MyClass() {
public Map<String, String> fromJSON(String json) throws Exception {
TypeReference<HashMap<String, String>> reference = new TypeReference<HashMap<String, String>>() {};
Map<String, String> map = null;
ObjectMapper mapper = new ObjectMapper();
map = mapper.readValue(json, reference);
return map;
}
}
发布于 2021-10-22 02:20:25
按照消息的建议,您可以创建一个命名的静态内部类:
private static final class MyTypeReference extends TypeReference<HashMap<String, String>> {}
public Map<String, String> fromJSON(String json) throws Exception {
TypeReference<HashMap<String, String>> reference = new MyTypeReference();
...
}
顺便说一句,FindBugs is not updated for years,所以最好用its successor或其他解决方案来取代它,如PMD,谷歌容易出错等。
https://stackoverflow.com/questions/69637586
复制相似问题