Constructors w/ Objects as parameters?

Say you have an object in you constructor like this:


Thing(Object o){
      this.o = o;
}

Now say that a variable in the object passed into the constructor on creation of an instance of the thing class. Does the object in the instance of the thing class get an updated variable too?

What I’m trying to say is when an object is passed into a constructor does it just clone that object over and then its done, or does it stay up to date with the object passed in?

Does this make sense?

The more or less definitive answer: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value

The short answer: No, it isn’t cloned, [icode]this.o[/icode] (the field named “o” of that Thing instance) holds a pointer to the object you gave the constructor.
You can write a simple test to prove it.

Awesome! Thanks for the info! +1

everything in java is a pointer, everything but the primitives

even Object blah = new Object(); is a pointer. The VM creates a new Object somewhere on the heap and the blah variable points to it.
cloning never happens unless you specifically program it. no new objects/clones are created if you dont use “new”

when using primitives that doesnt apply
int b = 4;
r = b; //makes a copy

If you want to copy an object, you can use a protected method clone()