不应直接存储或返回可变成员 - com.google.common.collect.ImmutableList - "false positive"

Mutable members should not be stored or returned directly - com.google.common.collect.ImmutableList - "false positive"

我们 return 一个不可变列表并得到严重的声纳警告 "Mutable members should not be stored or returned directly"

public List<A> getA() {
    return A;
}

A 在构造函数中被初始化为 ImmutableList.copyOf(B)。 是否可以考虑这些不可变的实现?

您可以创建类型为 ImmutableList 的变量 A,它应该不会引发问题。