Confused about Java passing methods (by value or reference) -
Confused about Java passing methods (by value or reference) -
this question has reply here:
is java “pass-by-reference” or “pass-by-value”? 57 answersguys, please, can clarify me?
as understand (please right me if wrong), when pass variables method or class i'm passing value, isn't it?
if it's true, why java has method .clone()?
why inquire question, because confused...here code: if pass variables using next code , modify them within dialog, original values (outside) changed.
dialogchoosepayment mdialogchoosepayment = new dialogchoosepayment(mcontext, (arraylist<payment>) defaultvalues.getpayment(), (arraylist<payment>) selectedvalues); mdialogchoosepayment.show();
but, if utilize next one, variables values (original variables outside) not changed.
dialogchoosepayment mdialogchoosepayment = new dialogchoosepayment(mcontext, (arraylist<payment>) defaultvalues.getpayment().clone(), (arraylist<payment>) selectedvalues.clone()); mdialogchoosepayment.show();
please, explain newbie =)
source: http://docs.oracle.com/javase/tutorial/java/javaoo/arguments.html
passing primitive info type arguments primitive arguments, such int or double, passed methods value. means changes values of parameters exist within scope of method. when method returns, parameters gone , changes them lost.
passing reference info type arguments reference info type parameters, such objects, passed methods value. means when method returns, passed-in reference still references same object before. however, values of object's fields can changed in method, if have proper access level.
java pass-by-reference pass-by-value
Comments
Post a Comment