私有数组在传递到另一个类(java)后更改值

私有数组在传递到另一个类(java)后更改值,java,Java,我有两门课。一班和二班。在Class1中,我创建了一个私有双tempPoint[]变量,并设置了一些值。将此变量传递给Class2并在Class2内更改tempPoint[]的值后,tempPoint[]的值在Class1中也会更改。我怎样才能避免呢 主要内容: 类别1: 类别2: 输出: 如果要确保没有人更改原始数组的内容,则需要传递数组的副本: class2.method2(tempPoint.clone()); 如果要确保没有人更改原始数组的内容,则需要传递数组的副本: class2.m

我有两门课。一班和二班。在Class1中,我创建了一个私有双tempPoint[]变量,并设置了一些值。将此变量传递给Class2并在Class2内更改tempPoint[]的值后,tempPoint[]的值在Class1中也会更改。我怎样才能避免呢

主要内容:

类别1:

类别2:

输出:


如果要确保没有人更改原始数组的内容,则需要传递数组的副本:

class2.method2(tempPoint.clone());

如果要确保没有人更改原始数组的内容,则需要传递数组的副本:

class2.method2(tempPoint.clone());

如果要确保没有人更改原始数组的内容,则需要传递数组的副本:

class2.method2(tempPoint.clone());

如果要确保没有人更改原始数组的内容,则需要传递数组的副本:

class2.method2(tempPoint.clone());
class2.method2(tempPoint.clone());