Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Programmer > Re: method para...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 7 Topic 52653 of 55513
Post > Topic >>

Re: method parameters

by Eric Sosman <esosman@[EMAIL PROTECTED] > May 11, 2008 at 02:34 PM

david wrote:
> Hello everyone, I am a new with JAVA and I have one problem now which
> I can not figure out now, maybe I am tired. Let's get to the problem.
> 3 small parts of the code:
> 
>         Boolean linksVault[][] = null;
>         if (!fLoadData(linksVault, args[0])) {
>             System.out.println("Kazkas blogai ir tiek");
>             System.exit(1);
>         }
> 
>     .........
> 
>     private static boolean fLoadData(Boolean[][] linksVault, final
> String fName) {
> 
>     .........
> 
>    linksVault = new Boolean[countTop][countTop];
> 
> So I send linksVault reference to the fLoadData, which then creates
> the matrix of Boolean object it everything is perfect with it inside
> that method, but outside it always get NullPointerException. It looks
> like linksVault does not point to the matrix, any ideas way?

     The linksVault in fLoadData is private to fLoadData and
not connected with the linksVault variable in the caller.  It
gets an initial value (null, in this case) from the method
call, but nothing fLoadData does to it afterward has any
effect on the caller.  When you assign a new value to linksVault
inside fLoadData, nothing happens to the completely independent
linksVault variable in the caller.

     Here's another example:

	void plusOne(int value) {
	    value = value + 1;
	}
	...
	int answer = 42;
	System.out.println("The Answer is " + answer);
	plusOne(answer);
	System.out.println("The Answer is " + answer);

Do you expect The Answer to change, just because of the
assignment inside plusOne?  If you say "Yes," then consider

	System.out.println("The Answer is " + 42);
	plusOne(42);
	System.out.println("The Answer is " + 42);

-- 
Eric Sosman
esosman@[EMAIL PROTECTED]

 




 7 Posts in Topic:
method parameters
david <David.Abdurachm  2008-05-11 11:22:05 
Re: method parameters
Eric Sosman <esosman@[  2008-05-11 14:34:33 
Re: method parameters
david <David.Abdurachm  2008-05-11 11:46:27 
Re: method parameters
Lew <lew@[EMAIL PROTEC  2008-05-11 14:54:21 
Re: method parameters
Patricia Shanahan <pat  2008-05-11 12:04:45 
Re: method parameters
david <David.Abdurachm  2008-05-11 12:13:54 
Re: method parameters
Mark Space <markspace@  2008-05-11 13:38:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 19:13:55 CST 2008.