Okay this is definitely a n00b question but here goes.
The way I understand it, is objects in Java are passed by value, not reference. How then do you alter a class member within a method by passing a reference to it to the method?
I know it is possible to do, because the method getRotationMatrix does it… ie if I write the following at the class level:
private float rotationMatrix[] = new float[9];
and then within a method I call:
SensorManager.getRotationMatrix(rotationMatrix, inclinationMatrix, gData, mData);
It will alter rotationMatrix. My question is how does that method change what is in the object I passed it if everything is passed by value?
The reason I ask is I am trying to write a method that does the same thing, but keep running into the pass-by-value conundrum. I’m trying to initialize a FloatBuffer by passing a reference to it to a method.
Yes objects are passed by value. But the Object is a reference so a copy of reference is passed. Using the reference you can modify the object but changing the reference will not have any effect on caller.
For example: