SonarQube 规则冲突

SonarQube Rules Conflict

SonarQube 报告 'Make "ids" transient or serializable' 这行代码:

private final List<String> ids;

所以我改成了:

private final ArrayList<String> ids;

并确保我的 public 接口(本例中的构造函数)仍然只使用一个接口:

public MyClass(List<String> ids) {
    this.ids = (ids == null) ? new ArrayList<>() : new ArrayList<>(ids);
}

这消除了第一个 SonarQube 警告,但现在它给出:

"ids"对象的类型应该是"List"这样的接口,而不是实现"ArrayList"。

我不想关闭所有使用接口而不是具体的规则 类,但仅针对这种情况。

您没有说明您使用的 Java 插件是哪个版本,但很可能是 3.4 之前的版本; that rule was relaxed 在 v3.4 中忽略私有字段。