为了减少可变性,我们应该使用
public void setValues(String[] newVals) {
this.vals = ( newVals == null ? null : newVals.clone() );
}
Run Code Online (Sandbox Code Playgroud)
要么
public void setValues(String[] newVals) {
this.vals = ( newVals == null ? null : Arrays.copyOf(newVals, newVals.length) );
}
Run Code Online (Sandbox Code Playgroud)