Suppose I have a class :
class Dummy{
public static ArrayList<String> varArray;
}
In another class I do this :
Class Dummy2{
void main()
{
ArrayList<String> temp = Dummy.varArray;
}
}
Now suppose in Dummy2
I add elements to temp
. Will the changes be reflected in Dummy.varArray
? Because this is what is happening in my program. I tried printing the address of the two and they both point to the same address. Didn't know static
field worked like this. Or am I doing something wrong?