我们有一些具有共享构造函数逻辑的常用模式的类:
public X(E... processors)
{
this(ImmutableList.copyOf(processors));
}
public X(Collection<E> processors)
{
this.processors = ImmutableList.copyOf(processors);
}
在这种情况下,容易出错的抱怨ConstructorLeaksThis
.../X.java:61: error: [ConstructorLeaksThis] Constructors should not pass the 'this' reference out in method invocations, since the object may not be fully constructed.
this(ImmutableList.copyOf(processors));
^
(see http://errorprone.info/bugpattern/ConstructorLeaksThis)
如果这种实现模式实际上是不安全的,我敢肯定它可以很容易地重构为静态方法,但我想问题是,不安全吗?也许这不是编译器检查想要检测的?