Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34633
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Robert Klemme <shortcutter@googlemail.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Are you sure, Mr. Gosling? |
| Date | Tue, 14 Jun 2016 19:10:31 +0200 |
| Lines | 58 |
| Message-ID | <dsas48Fm2pvU1@mid.individual.net> (permalink) |
| References | <Gosling-20160604185910@ram.dialup.fu-berlin.de> <niva2t$13sk$1@gioia.aioe.org> <nivehs$9e0$1@dont-email.me> <nivlkk$1mm2$1@gioia.aioe.org> <nj14i9$ufe$1@dont-email.me> <1eb77568-ae31-4316-ac21-a33db79c5aa4@googlegroups.com> <nj3s6h$l08$1@dont-email.me> <nj471k$f77$2@Gaia.teknon.de> <drm6bcFhke1U1@mid.individual.net> <5c864ac4-9634-4c88-9d6b-d14dbf3b3886@googlegroups.com> <drodg0FejbU1@mid.individual.net> <746532a2-c6db-4d58-afc0-1cc57440eff5@googlegroups.com> <nj7asv$j9j$1@dont-email.me> <9ecc34ba-fac1-45ed-88cb-71403c7c906d@googlegroups.com> <drr804FhojnU1@mid.individual.net> <60f13013-4df5-453d-bf62-78283e57e79b@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net qEWHsLwk4ggklI4SHMo9vgdSlT3FThwY+ITNMBmB1IJr7/sOU= |
| Cancel-Lock | sha1:vmKZz/crHAUPI5ZwJ1uuMQVkO/Q= |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 |
| In-Reply-To | <60f13013-4df5-453d-bf62-78283e57e79b@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:34633 |
Show key headers only | View raw
On 10.06.2016 21:20, Lew wrote:
> On Wednesday, June 8, 2016 at 11:55:13 AM UTC-7, Robert Klemme wrote:
>> On 08.06.2016 15:31, Eric Douglas wrote:
>>> Defaults from clone() to consider (if we don't want these, we either
>>> need to specify the alternative in the copy constructor, or replace in
>>> the clone method on the new instance returned from super.clone()):
>>> Immutable objects get copied by value, bucket objects get copied by
>>> reference.
>>
>> This is wrong. Objects ("reference types") are copied by reference by
>> Object.clone() - regardless of whether they are mutable or not. Only
>> primitive types are copied by value.
>
> That isn't correct. References are copied, by default, but they are
> copied by value. When 'clone' is overridden appropriately, those
> references are dereferenced, and the values to which they point are
> copied. However you look at it, it is values that are copied - either
> pointer values or primitive values.
Yes, references (pointers) are copied by value, i.e. there is a new
object that has a pointer to the same object. That is the default
behavior of clone(). This is different from what Eric had written (see
above) and which prompted my response.
Now, of course, if you override it typically you would retain some
references (e.g. to immutable objects) and provide new values for others
(e.g. to collections), typically by creating a new object one way or
another (i.e. invoking clone(), a constructor, a factory method or
something else) or using a default value (e.g. null).
> Copy-by-reference means that the original reference will point to the
> new object, which is not what we want nor what 'clone' does.
I am not sure. Now that we have talked about it so much I am not sure
any more that "copy by reference" is actually properly defined. It
seems a parallel construction to "call by reference" but that describes
another situation, namely a non-copy of a value. You could describe
this as copying an immutable pointer (in C++ you cannot change what a
reference points to, as opposed to a pointer).
> This is similar to the logic that proves that method arguments in
> Java are always passed by value. Java doesn't actually have
> references, as C++ programmers and others understand them. It has
> pointers.
Well, underneath all are pointers (to memory addresses). In C++ the
difference is that you can change a pointer (i.e. where it points to)
but not a reference. In that sense references in Java are really pointers.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Are you sure, Mr. Gosling? Arne Vajhøj <arne@vajhoej.dk> - 2016-06-04 15:27 -0400
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-04 16:43 -0400
Re: Are you sure, Mr. Gosling? Arne Vajhøj <arne@vajhoej.dk> - 2016-06-04 18:44 -0400
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-05 08:05 -0400
Re: Are you sure, Mr. Gosling? Arne Vajhøj <arne@vajhoej.dk> - 2016-06-05 08:31 -0400
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-06 05:22 -0700
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-06 09:00 -0400
Re: Are you sure, Mr. Gosling? v_borchert@despammed.com (Volker Borchert) - 2016-06-06 16:06 +0000
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-06 22:56 +0200
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-07 05:08 -0700
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-07 08:41 -0400
Re: Are you sure, Mr. Gosling? Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-07 13:14 +0000
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-07 06:30 -0700
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-07 19:10 +0200
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-07 10:22 -0700
Re: Are you sure, Mr. Gosling? Mike Amling <mamling@chaff.us> - 2016-06-07 15:31 -0500
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-08 06:31 -0700
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-08 10:41 -0400
Re: Are you sure, Mr. Gosling? Eric Douglas <e.d.programmer@gmail.com> - 2016-06-08 10:21 -0700
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-08 14:10 -0400
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-08 20:54 +0200
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-08 16:36 -0400
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-08 23:11 +0200
Re: Are you sure, Mr. Gosling? Lew <lewbloch@gmail.com> - 2016-06-10 12:20 -0700
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-14 19:10 +0200
Re: Are you sure, Mr. Gosling? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-07 17:12 -0400
Re: Are you sure, Mr. Gosling? Robert Klemme <shortcutter@googlemail.com> - 2016-06-07 23:25 +0200
Re: Are you sure, Mr. Gosling? Arne Vajhøj <arne@vajhoej.dk> - 2016-06-07 17:33 -0400
Re: Are you sure, Mr. Gosling? Arne Vajhøj <arne@vajhoej.dk> - 2016-06-06 21:18 -0400
csiph-web