My question resembles a lot the battle between "is java pass-by-value or pass-by-reference". But I still can't understand what happens when I pass an object in a function. For example let's say that I have a huge HashMap and I want it to be accessible by every object and every class. So I pass it as an argument to all functions that need it. To be more specific, I create this HashMap in the main function and then I have some objects that require it.
main()
{
HashMap<Integer,Set<Integer> dataset=readDatasetfromFile(file);
ArrayList<Object> objects=new ArrayList();
//assume that I create and fill the list with objects
for(int i=0;i<objects.size();i++)
{
int variable=objects.get(i).doSomething(dataset);
}
}
But I don't understand if it copies it or not. There is no point in copying it every time I call a function, because that is a waste of time. It would be nice if it just passes the object as a reference. Thank you.
As I said none of the answered posts explicitly says if the whole object is copied bit by bit to the function or no, and that is my main question. So I don't see any resemblance to other questions.