In Java, when we pass a java object argument to method myMethod((MyObject) myObject), it is basically like passing a reference to object in C++ like myFunction(& myObject). In such cases java developer has pretty much the same freedom like C++ programmer, if he wants to pass a reference he just passes an object, if he wants to get it copied, he does it manually in method.
But here is my question:
Let's say i have three different arrays with specific type of objects MyObject
MyObject[] myObjectsOne
MyObject[] myObjectsTwo
MyObject[] myObjectsThree
I need to have them separately, but i also need one alternative array which would be like a summary of those three mentioned above - for example used as single object to display the content of all three.
Scenario: To create the fourth array, which would represent the values of first three without copying the values actually anywhere. (Not allocating extra memory for these values)
In C++ i would just create a table with references to corresponding objects in those three tables.
I have always thought that in Java it is just being made for us, but when i started thinking about it, i am not really sure.
We have now also: MyObject[] myObjectsFour
And after performing..
myObjectsFour[0] = myObjectsOne[0]; ..does accessing myObjectsFour[0] and myObjectsOne[0] mean actually accessing the same object on memory level? Like i understand, it must be like that, if it was not myObjectsFour[0] = myObjectsOne[0].clone();