-
passing String references
Hi, I was wondereing if someone could help me with a problem I am having with
strings.
I have a call to OFileName(iFileNm)
In get OFileNm I have
private void getOFileNm(String file)
{
file = "C:\\jdocs\\j2sdk1_3_0-doc.zip";
}
However, String iFileNm does not get changed by the function call. I would
think that the call would pass the reference to the string, and in the methode
that reference would get changed to point to "C:\\jdocs\\...", however this
does not seem to be happening. What am I doing wrong?
Thanks for any help you can give.
-Harry
-
Re: passing String references
Hey Harry,
how about having a cup of coffee and sit back and look over your code again?
Seemed to work last time hehehe
Patrick
"Harry" <harrytuttle89@hotmail.com> wrote:
>
>Hi, I was wondereing if someone could help me with a problem I am having
with
>strings.
>
>I have a call to OFileName(iFileNm)
>
>In get OFileNm I have
>private void getOFileNm(String file)
> {
> file = "C:\\jdocs\\j2sdk1_3_0-doc.zip";
> }
>
>However, String iFileNm does not get changed by the function call. I would
>think that the call would pass the reference to the string, and in the methode
>that reference would get changed to point to "C:\\jdocs\\...", however this
>does not seem to be happening. What am I doing wrong?
>
> Thanks for any help you can give.
> -Harry
-
Re: passing String references
Here's what happened. First you had a variable iFileNm that referred to a
certain string. Then you called the OFileName method, and that caused one
of its local variables, file, to refer to that same string. Then you
changed file to refer to a different string. Of course this had no effect
on the first variable. (file referred to the same string as iFileNm did.
It didn't refer to iFileNm.)
Remember that objects in Java are always references to objects. And
remember that Strings are objects, too. Keep reminding yourself of this
because it seems to be an unobvious concept.
You didn't post the entire code of your method but if you wanted it to
return a String, the way to do that is:
private String getOFileNm() {
... return "blabla";
}
Harry <harrytuttle89@hotmail.com> wrote in message
news:39565ded$1@news.devx.com...
>
> Hi, I was wondereing if someone could help me with a problem I am having
with
> strings.
>
> I have a call to OFileName(iFileNm)
>
> In get OFileNm I have
> private void getOFileNm(String file)
> {
> file = "C:\\jdocs\\j2sdk1_3_0-doc.zip";
> }
>
> However, String iFileNm does not get changed by the function call. I
would
> think that the call would pass the reference to the string, and in the
methode
> that reference would get changed to point to "C:\\jdocs\\...", however
this
> does not seem to be happening. What am I doing wrong?
>
> Thanks for any help you can give.
> -Harry
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks