How to copy an object by value, not by reference
Posted
by Blankman
on Stack Overflow
See other posts from Stack Overflow
or by Blankman
Published on 2010-04-12T17:53:53Z
Indexed on
2010/04/12
18:03 UTC
Read the original article
Hit count: 200
java
I want to make a copy of an object, then after some logic, re-assign the original object the value of the copy.
example:
User userCopy = //make a copy
foreach(...)
{
user.Age = 1;
user.ID = -1;
UserDao.Update(user)
user = userCopy;
}
I don't want a copy by reference, it has to be a copy by value.
The above is just a sample, not how I really want to use it but I need to learn how to copy by value.
© Stack Overflow or respective owner