W
www
Hi,
My class is like following:
public MyClass
{
private double[] _dataArray = new double[100];
public void setDataArray(double[] inputArray) //not good!
{
_dataArray = inputArray;
}
public double[] getDataArray()
{
return _dataArray; //privacy leak
}
}
An Eclipse plugin pointed out that both places could be causing privacy
leak. I know, in Java, array is a tricky data type. It is sort of like
Class variable. So passing array reference is like passing an object
reference: still one object, but with multiple references to it. Each
reference has the ability to modify the object.
What should I do to avoid such a potential problem?
Thank you very much.
My class is like following:
public MyClass
{
private double[] _dataArray = new double[100];
public void setDataArray(double[] inputArray) //not good!
{
_dataArray = inputArray;
}
public double[] getDataArray()
{
return _dataArray; //privacy leak
}
}
An Eclipse plugin pointed out that both places could be causing privacy
leak. I know, in Java, array is a tricky data type. It is sort of like
Class variable. So passing array reference is like passing an object
reference: still one object, but with multiple references to it. Each
reference has the ability to modify the object.
What should I do to avoid such a potential problem?
Thank you very much.