Re: pass by reference
- From: Donkey Hot <spam@xxxxxxxxxxxxxxxxx>
- Date: 04 Apr 2008 15:31:40 GMT
"angelochen960@xxxxxxxxx" <angelochen960@xxxxxxxxx> wrote in news:0a4ad57b-
60d2-4b7a-93c5-e53b20628c81@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
Hi guys,
Thanks for all the answers, I'm kind of surprised that a simple
question got so many answers! is this statement correct:
Everything in Java are passed by value, in the case of an object, a
reference to the object is passed, which is a value too, updating the
fields in the reference does reflect the changes. anyway, maybe I
should not try to understand java in a C++ manner.
but i can't help, String is a object, so a reference should be the one
passed, and why we can not update the field in the String object? and
then where is the field of the String?
Yes, I was wrong in my
public void myFunc(String s) {
s = "123";
}
because that compiles exactly as
public void myFunc(String s) {
s = new String("123");
}
If the String class had a method setValue() we could write
public void myFunc(String s) {
s.setValue("123");
}
but it does not, and we can't.
Some kind of a wrapper class is needed with the methods required.
.
- Follow-Ups:
- Re: pass by reference
- From: Roedy Green
- Re: pass by reference
- From: Roedy Green
- Re: pass by reference
- References:
- pass by reference
- From: angelochen960@xxxxxxxxx
- Re: pass by reference
- From: Chase Preuninger
- Re: pass by reference
- From: Andreas Leitgeb
- Re: pass by reference
- From: Lew
- Re: pass by reference
- From: Andreas Leitgeb
- Re: pass by reference
- From: angelochen960@xxxxxxxxx
- pass by reference
- Prev by Date: Re: pass by reference
- Next by Date: Re: PDF's sent through tomcat/apache
- Previous by thread: Re: pass by reference
- Next by thread: Re: pass by reference
- Index(es):
Relevant Pages
|