Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: Objects only passed by copy? Date: Sat, 08 Sep 2012 19:57:04 -0700 Organization: Canadian Mind Products Lines: 30 Message-ID: References: <6e06860b-4c72-4f4b-8892-69aa4242a4dc@googlegroups.com> Reply-To: Roedy Green NNTP-Posting-Host: K2Qzzs3EAqXk5RLzfhxcSw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: csiph.com comp.lang.java.programmer:18615 On Sat, 8 Sep 2012 17:22:05 -0700 (PDT), Luft wrote, quoted or indirectly quoted someone who said : >I'm learning JAVA and read that EVERYTHING in JAVA is passed by copy and that in the case of objects the internal variables share a reference but that objects are also passed by copy. > >I'm trying to think of a piece of code that would demonstrate this but can't think of anything off the top of my head. that is not correct. Objects are not cloned. References to single object as passed around. Write a method that takes an object parameter with a mutable field. Change it in the method. If it copied, you would see the mother object changed as well. You won't. see http://mindprod.com/jgloss/object.html and follow links This drives you crazy as a newbie, but once you get it is seems so easy and so obvious, it is hard to understand why you had so much trouble. -- Roedy Green Canadian Mind Products http://mindprod.com A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. ~ Max Planck 1858-04-23 1947-10-04