|
Re: Newbie:how to get a reference out of a method
|
Posted: Jan 1, 2003 12:00 PM
|
|
This is not possible in Java. Everything (method parameters) in Java is passed by value. When you are passing j to foo() then j is passed by value and when you call foo() then p has a copy of j, which in your case will be null. By copy here I meant the copy of the reference and not the copy of whole object. If you assign a new object reference to p then it is assigned to p only and j still refers to null. So, you cannot make j refer to another object inside foo(). If you want to still return a boolean from foo() then you can set the value of p in some instance variable and get it as: if ( foo() ) { j = get the Value of p here which you created in foo(); }
|
|