Click here to Skip to main content
15,896,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public class A{
    void set(A k){
        k = null;
    }
}


        A a = new A();
        A b = new A();
        System.out.println(a);
        System.out.println(b);
        a.set(b);
        System.out.println(b);



The outputs:
business.CharacterCard$A@61de33
business.CharacterCard$A@14318bb
business.CharacterCard$A@14318bb
Posted

1 solution

Java is a "pass by value" language, to quote David Flanagan's "Java in a Nutshell". So when you call a.set(b), the reference to b is copied into the local "k" of the method. That is then modified to null (as you can see if you use a debugger), but nothing has happened to the "b" in the caller.
Remember to vote for the answer, and mark it accepted if you like it. If you want to reply to this, make a comment, not another answer.
 
Share this answer
 
Comments
jibeex 3-Oct-10 16:07pm    
thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900