This is not true, Java

This is not true, Java _always_ passes by value. But if the parameter is an Object, you are passing the address of the Object (i.e. the reference) by value (you certainly don't copy the entire object onto the stack). Thus you are passing a reference by value.

Therefore, if you send the object a message (e.g. call a method on the Object) that changes its state, then this is observable outside the method body. But if you assign to the parameter within the method, you do not affect the caller's reference (it will still point to the same Object). And it sounds like Python works the same way.

Reply

The content of this field is kept private and will not be shown publicly.
Type this to prove you are human.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Ads (you can disable these if you log in)