下面是 intellij 发出警告的代码片段Suspicious collections method calls
,但我不明白为什么。我唯一能想到的是,也许 intellij 认为其中一个列表可能为空,但这也会引发相同的错误。
这是 Intellij 的错误,还是真的有一些我没有想到的极端情况?
public class Foo {
public static void main(String[] args) {
List<String> foo = Arrays.asList("a", "b", "c");
List<String> bar = new ArrayList<>(foo);
bar.remove(foo); // Warning: 'List<String>' may not contain objects of type 'List<String>'
}
}
Run Code Online (Sandbox Code Playgroud)
public class Foo {
public static void main(String[] args) {
List<String> foo = Arrays.asList("a", "b", "c");
List<String> bar = new ArrayList<>(foo);
if (foo != null && bar !=null) {
bar.remove(foo); // Warning: 'List<String>' …
Run Code Online (Sandbox Code Playgroud)