Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clean method to pass object parameter

Status
Not open for further replies.

zhuzhengyu

Technical User
Jul 21, 2000
19
CN
As we all know,java has two parameter-passing methods while call a function:
1.to primitive type,it use value
2.to object, it use reference.
So here is the question:
when I use a method in a class provided by others,and this function need pass some objects as auguments.So there is possibility that after calling this function,the object's value has been changed.Is there any clean method to avoid this and guarantee the object is same before and after calling the function.
I know one way is:everytime before I use a function,I clone an object.But the way is too tedious and not fesible in reality.
 
You can create the copy inside your function rather than prior to the call. In theory, you could final the parameter, but if you pass THAT to another, you can change it. "final" isn't really final.

Or use C++.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top