J
Jax
I dont seem to fully comprehend references to objects yet.
Lets say for example I do this;
Customer c = new Customer();
Customer c1 = c;
I understand that if I change c1, I also change c as they
are both referencing the same piece of data.
But this isn't always the case it would seem.
Sometimes I take a reference out, change it and then go
back to the original which still has it's old value.
When does this reference copying apply and when does it
not?
I'm confused as I seem to be getting mixed results.
What I would like to know are the rules that state when it
happens and under what conditions it doesn't happen.
For example if I have an object that contains an arraylist
of customers and I grab one of those i.e:
foreach(Customer c1 in theCase.Customers)
{
if(c1.Something == something)
myCustomer = c1;
}
myCustomer.Name = "Something different";
Does this now change the customer in theCase as well?
Also on this topic, does the clone method give you a clean
version that wont effect the orignal? If not, what method
of copying would I need and how would I begin to implement
this?
Many thanks for any of you kind sirs or madames (are there
female coders?) who get me out of my muddle.
jax
Lets say for example I do this;
Customer c = new Customer();
Customer c1 = c;
I understand that if I change c1, I also change c as they
are both referencing the same piece of data.
But this isn't always the case it would seem.
Sometimes I take a reference out, change it and then go
back to the original which still has it's old value.
When does this reference copying apply and when does it
not?
I'm confused as I seem to be getting mixed results.
What I would like to know are the rules that state when it
happens and under what conditions it doesn't happen.
For example if I have an object that contains an arraylist
of customers and I grab one of those i.e:
foreach(Customer c1 in theCase.Customers)
{
if(c1.Something == something)
myCustomer = c1;
}
myCustomer.Name = "Something different";
Does this now change the customer in theCase as well?
Also on this topic, does the clone method give you a clean
version that wont effect the orignal? If not, what method
of copying would I need and how would I begin to implement
this?
Many thanks for any of you kind sirs or madames (are there
female coders?) who get me out of my muddle.
jax