小编nan*_*tek的帖子

Intellij:警告:“List<String>”可能不包含“List<String>”类型的对象(可疑集合方法调用)

下面是 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)

java intellij-idea intellij-14

1
推荐指数
1
解决办法
1890
查看次数

标签 统计

intellij-14 ×1

intellij-idea ×1

java ×1