Bhu*_*han 5 java static-analysis pmd literals
我有以下代码。我收到“避免在条件语句中使用文字”。PMD 中第 5 行发出警告。
List<Object> listObj = getData();
 if (listObj.isEmpty()) {
      throw new NoEntity("No entity found for given Device.");
 }
 if (listObj.size() > 1) {
      throw new MultiEntity(
          "Multiple entity record found for given Device.");
 }
我不喜欢将全局静态最终 int 变量的值设置为 1 并在 if 条件中使用它。还有其他解决方案吗?
小智 2
如果您使用的是 Apache Commons Lang,可以在 NumberUtils 中找到它https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/math/NumberUtils.html#INTEGER_ONE
| 归档时间: | 
 | 
| 查看次数: | 8287 次 | 
| 最近记录: |