我有一个类的复制构造函数,但Android Studio代码判断抛出了一个我不理解的警告:
构造函数副本中的可疑赋值
public class CpuVariable extends BaseIdentifier {
private int memoryType;
private byte[] value;
public CpuVariable(@NonNull CpuVariable other) {
super(other);
this.memoryType = other.memoryType;
if (other.value != null) {
this.value = java.util.Arrays.copyOf(other.value, other.value.length);
}
}
}
将代码更改为
this.value = other.value
将删除警告,但这不是一个选项,因为我需要为字段创建深度副本或克隆.
我是否编写了错误的代码,或者忽略或 suppress 警告是否安全?