Java method doesn't change parameter objects -
this question has answer here:
i have function this:
public static int partition(list list, listelement eleml, listelement elemr){ listelement elemx; ... elemr = elemx.next; return x; }
and @ end of funktion elemr changed, after calling function main method parameter elemr has still same value before function call. what's problem? how can change listelement , "save" change after function called without changing return type listelement (i need integer return value too)?
java functions parameters called reference name, meaning when place object function argument, jvm copies reference's value new variable, , passes function argument. if change contents of object, original object change, if change actual value of reference, these changes destroyed when function ends.
i hope helps
Comments
Post a Comment