-4

According to my understanding, Java does not have pointer, so any function parameter can not be modified in a function call, say even a parameter value is modified inside a function call, but after the function call the parameter's value still keeps the previous value

Am I right?

Rui
  • 2,967
  • 4
  • 27
  • 54
  • Please provide some code examples to indicate what you mean. In doing so, you may likely discover the answer for yourself. – Roman Apr 15 '16 at 15:02
  • You would be right regarding primitive types, but not with object types e.g. If you pass a List to a method and that method adds to the list, then it will have that added value after you leave the method. – ManoDestra Apr 15 '16 at 15:04
  • for instance, public void change(byte[] array), if this parameter array's values are changed during the functional call, is this array kept unchanged after the functional call? – Rui Apr 15 '16 at 15:04
  • @user1928863 There's nothing stopping you from trying. However the duplicate answers your question. – Paul Boddington Apr 15 '16 at 15:05
  • Where is the duplicate? – Rui Apr 15 '16 at 15:07
  • Try refreshing the page. The link should appear under the question title. – Paul Boddington Apr 15 '16 at 15:09

1 Answers1

0

Yes, you are right. Java only have call by value for function parameter. After function has finished execution, the parameter it used will no longer referenced by others.ie, garbage.

Maxwell Cheng
  • 790
  • 7
  • 16