Collections.singletonList
即使列表中的值是不可变的,SonarLint 似乎也认为是可变的。这是一个错误还是规则不够智能,无法检查列表类型的可变性?
public static final List<String> STRING_LIST = Collections.singletonList("myString");
Run Code Online (Sandbox Code Playgroud)
Collections.immutableList
相反,即使列表中的值是可变的,使用似乎也会消除此错误。
public static final List<Point> POINTS = Collections.unmodifiableList(Collections.singletonList(new Point(1, 2)));
Run Code Online (Sandbox Code Playgroud)
以上运行 SonarQube 6.2。