You never pass by value, so you're in essence always dealing with =20
pointers.
With your example, you merely made a1 point at a different object, a =20
new string, instead of the second string in the array.

If you however call a self-modifying method on a1 while it's pointing =20=

at the array string, it'll also change in the array, as it's still =20
pointing at the same object.

* Iñaki Baz Castillo <> (18:24) schrieb:
>> If you however call a self-modifying method on a1 while it's pointing at
>> the array string, it'll also change in the array, as it's still pointing at
>> the same object.
>
> No, that's not true. Demostration:

I=C3=B1aki Baz Castillo wrote:
> I thought that "=3D" was also a "self-modifying"
> method.

=3D isn't a method. If it was a method, x=3Dy could not result in x having =
a=20
different object_id than before. It could also not result in x having a=20
different class than before.
What x =3D y does, is that it makes x point to the same object as y which=20
doesn't affect the old object x pointed to at all.
Basically methods change the object (or not) and =3D changes the variable.
I don't think it's possible to have a =3D method without static typing.

Note though that in "foo.bar =3D baz" bar=3D actually is a method on foo an=
d not=20
an assignment operation.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!