View Full Version : Java Question


Ender
01-05-04, 08:24 PM
In Java when you pass a vector, do you really pass the vector, or a copy or what?

AntonK
01-05-04, 08:41 PM
Everything except the primites (char, int, double, float, etc) can be thought of as a pointer. In java they are called references. So when you pass a vector its like passing a pointer to a vector. Most objects have a clone() method, so that can be used to pass an actual copy if you should need to. This is similar to the copy constructor in C++.

-AntonK

mouse
01-08-04, 03:44 AM
Most objects have a clone() method, so that can be used to pass an actual copy if you should need to.

I wonder, is there a way to avoid writing clone methods for your own home brewed classes by means of a generic method using some form of introspection for running down properties?

aporia
01-16-04, 11:04 AM
You're asking about pass-by-value versus pass-by-reference semantics. These links will answer your question.

http://www-106.ibm.com/developerworks/java/library/j-passbyval/
http://www.cs.umd.edu/class/sum2003/cmsc420/sum3v101/node6.html
http://www.yoda.arachsys.com/java/passing.html
http://academic.regis.edu/dbahr/GeneralPages/IntroToProgramming/JavaPassByValue.htm

-Nick