Re: Call by reference in Java?
From: Dale King (kingd[at]tmicha[dot]net)
Date: 02/27/04
- Next message: E.C.: "Re: Java Regex"
- Previous message: Jon Skeet: "Re: Getting string from an Arraylist?"
- In reply to: Ekim: "Call by reference in Java?"
- Next in thread: Tony Morris: "Re: Call by reference in Java?"
- Reply: Tony Morris: "Re: Call by reference in Java?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 Feb 2004 13:48:04 -0500
"Ekim" <the.newsletter@gmx.net> wrote in message
news:c1ip91$1k981t$1@ID-222835.news.uni-berlin.de...
>
> I've a simple, maybe stupid question.
> How does a "pointer" look like in Java? I've just tried a "*" like in C,
but
> it didn't work.
> Now I'm not sure in which way I can solve my problem.
>
> The task is, that I want to call a procedure, and the parameters shall be
> call by reference.
> For example, this is my procedure call:
> checkParameter(kosten_pro_liter, liter, kosten, gesamt_km);
>
> The definition of my procedure looks like this:
> public void checkParameter(String strPreisProLiter, String
strAnzahlLiter,
> String strPreis, String strGesamtkilometer) {.....}
>
> What can I do so that after the procedure was executed, the parameters
have
> the value they have been given within the procedure?
As others have pointed out it is a good thing that you cannot pass by
reference in Java. The desire to pass by reference is usually a good
indicator that there is a flaw in your design. Usually it is caused by not
thinking in an object-oriented manner and thinking in a procedural mindset.
The fact that you used the word procedure 4 times is also a pretty good
indication of that ;-)
The solution is not to try to figure out how to emulate the behavior of C,
but to fix the design. Fixing the design implies coming up with the best
abstraction to fit the problem at hand. Without more knowledge of what
checkParameter is supposed to be doing I can't tell you what the best
abstraction is. I'm guessing the real issue may be that you are trying to do
to much in one method call and it should be separate method calls, but the
non-English names don't tel me what the method is supposed to do.
-- Dale King
- Next message: E.C.: "Re: Java Regex"
- Previous message: Jon Skeet: "Re: Getting string from an Arraylist?"
- In reply to: Ekim: "Call by reference in Java?"
- Next in thread: Tony Morris: "Re: Call by reference in Java?"
- Reply: Tony Morris: "Re: Call by reference in Java?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|