The reason to take this problem out again, because we operate Java objects (object) are all through the object of the reference (object references), reference can be interpreted as pointers, easy for people to correspond to the C + + address above. There is no harm in discussing the discussion.
When you pass a basic data type variable, the direct value is not confusing, but when passing the object, it should be understood to pass the value of the object reference, but the value is not the object itself, but the object, that is, you let another reference point to the object.
--java passes the object reference by value.
Take the following simple procedure as an example:
Package test;
public class Blogtest
{
public void modifyaaa (int x, java.util.ArrayList list)
{
x + 5;
System.out.println ("x=====" + x);
List.add (New Java.util.Date ());
System.out.println (List.size ());
}
public static void Main (string[] args)
{
blogtest blogtest = new Blogtest ();
int i = 5;
java.util.ArrayList list = new Java.util.ArrayList ();
System.out.println ("i=======" + i);
System.out.println ("list.size () = =" +list.size ());
blogtest.modifyaaa (i, list);
System.out.println ("i==new==" + i);
System.out.println ("list.size () = =" + list.size ());
}
}
/*
The result of the run is this
i=======5
list.size () ===0
x=====10
1
i==new==5
List.size () ==new== 1
*/
This indicates that the following events occurred during parameter passing: the int variable I was copied to int x, and the value of x in the MODIFYAAA () method does not affect the value of I in the main function, which is, of course, a variable survival interval that is well understood. But the list in the main function also changes after discovering that the reference to the list object is passed to the MODIFYAAA () method. That's what this is about. When passing an object reference, the formal parameter gets a reference copy of the argument object, and two references all point to the same list object, so the formal parameter changes the list and can also be reflected in the argument.