I've seen the following in legacy code:
public void someFunction(List myList){
List myList2 = myList;
}
Is there a good reason to re-assign parameters as local variables in a function?
I've seen the following in legacy code:
public void someFunction(List myList){
List myList2 = myList;
}
Is there a good reason to re-assign parameters as local variables in a function?
Not really. Aliasing or reuse of names should be avoided, in my opinion.
It depends on the language. In some cases, you may want to make changes to the "copy" later on - and in some languages/situations changing the original parameter will make changes to what the caller sees.
If you could say which language you're talking about (Java?) and give a concrete example, that would help us to explain.
There's no good reason to do this, with pass-by-value parameters. This looks like a not-quite-fluent developer, recalling that another language he's worked with bit him if he didn't work on copies of his parameters.
Could be a personal style. Or a failed attempt to create a new reference? I am pretty sure as-is the compiler discards myList2 in favor of myList.