I would appreciate some help with the following, asked previously, not addressed in older questions related to Java and references.
Java is pass by object reference, years ago we called references, pointers. I am assuming this in predicting the output, however, even when I make tortVals and vraiVals aliases of each other, and expect for v1[1] and v2[1] to be the same, they are not. v2[1] still has a value of 6. I have not seen this addressed in existing issues, and still am asking for help. Same thing happens with the array of strings - the array arguments are pointers, yet the changes expected do not follow. Specifically, v2[1] remains 6, v3[1] is set to 'huit', instead of what I would expect, 'trois'. Thanks, Jacques
Here is my prior question: I have a small sample piece of code below - I predicted the output (print) would be 5 5 trois, because of the references. I got it wrong, it's 5 6 huit. Given that references allow for the area 'pointed to' to be changed, what am I missing? Help much appreciated, obviously this is a test case for a bigger scenario.
public static void main(String[] args) {
essayer();
}
public static void resetVals(int[] vraiVals, int[] tortVals, String[] noms) {
vraiVals[1] = 5;
tortVals = vraiVals;
noms[1] = new String("huit");
noms = new String[3];
noms[1] = new String("trois");
}
public static void essayer() {
int[] v1 = {1,2,3};
int[] v2 = {5,6,7};
String[] v3 = {"un", "deux", "trois"};
resetVals(v1, v2, v3);
System.out.println(v1[1] + " " + v2[1] + " " + v3[1]);
}