Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #18615
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Objects only passed by copy? |
| Date | 2012-09-08 19:57 -0700 |
| Organization | Canadian Mind Products |
| Message-ID | <ob1o485fcnj7gdhi596om6dghp4adfun8h@4ax.com> (permalink) |
| References | <6e06860b-4c72-4f4b-8892-69aa4242a4dc@googlegroups.com> |
On Sat, 8 Sep 2012 17:22:05 -0700 (PDT), Luft <edamron@spamcop.net> 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
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Objects only passed by copy? Luft <edamron@spamcop.net> - 2012-09-08 17:22 -0700
Re: Objects only passed by copy? Arne Vajhøj <arne@vajhoej.dk> - 2012-09-08 20:59 -0400
Re: Objects only passed by copy? Arne Vajhøj <arne@vajhoej.dk> - 2012-09-08 21:02 -0400
Re: Objects only passed by copy? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-08 21:30 -0400
Re: Objects only passed by copy? Lew <lewbloch@gmail.com> - 2012-09-30 17:23 -0700
Re: Objects only passed by copy? Roedy Green <see_website@mindprod.com.invalid> - 2012-09-08 19:57 -0700
Re: Objects only passed by copy? Roedy Green <see_website@mindprod.com.invalid> - 2012-09-30 13:50 -0700
csiph-web