Quote (ice060788 @ Nov 6 2014 07:08pm)
My confusion lies with this part of the example code:
Code
System.out.println("The arrays are identical: " + (data1 == data2));
No methods are being called and the answer should return false according to the key, but instead I get true. This part of the code isn't calling any of my methods so that's why I'm confused about it. I'm fine with the last two lines of the code because they should be true true. The first part is what's confusing me. The only reason why I think it should be false is because it should be comparing the memory location of the arrays but if that's true then I not sure what's wrong with my code because I don't call any methods in that line of code.
oh, my mistake. i thought you were confused about the bottom two.
ok.
for clarity, these are the two lines of code we're interested in:
Code
stat1.setData(data1);
double[] data2 = stat1.getData();
and here's what setData does:
Code
public void setData(double[] d)
{
data = d;
}
public double[] getData()
{
return data;
}
So you're essentially doing this:
Code
double[] data = data1; // from setData
double[] data2 = data; // from getData
if we ignore the middle man, you're doing this:
Code
double[] data2 = data1;
Can you see that data1 and data2 are the exact same object?
This post was edited by carteblanche on Nov 6 2014 06:16pm