| Author |
How to modify method parameters?
|
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Hi all, I am having a method which takes a couple of strings as parameters. The class which uses this method may sometimes send null parameters. In my method I am checking the parameter values. If any of the parameter is null I am assigning some value to it.
When I use the sonar plugin it reports that "Assignment of parameter x is not allowed". What is the right approach to assign a value to a method parameter?
Can anyone please tell me? Thank you all in advance. Good day.
|
Love all, trust a few, do wrong to none.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4736
|
|
chaitanya karthikk wrote:Hi all, I am having a method which takes a couple of strings as parameters. The class which uses this method may sometimes send null parameters. In my method I am checking the parameter values. If any of the parameter is null I am assigning some value to it.
When I use the sonar plugin it reports that "Assignment of parameter x is not allowed". What is the right approach to assign a value to a method parameter?
Can anyone please tell me? Thank you all in advance. Good day.
Without seeing the code, it's very hard to tell. Please supply an SSCCE.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
chaitanya karthikk
Ranch Hand
Joined: Sep 15, 2009
Posts: 779
|
|
Winston Gutkowski wrote:
Without seeing the code, it's very hard to tell. Please supply an SSCCE.
Winston
Hi Winston, thanks for the reply. This is the code
Now I understood why I should not change the parameter directly, because it messes up the things/code. Now I replace the above code with
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
|
chaitanya, Winston gave you that link for a reason. Is it really too much trouble click the link and go through that page?
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32627
|
|
chaitanya karthikk wrote: . . . I should not change the parameter directly, because it messes up the things/code. . . .
No, it doesn’t. It doesn’t mess anything up. To find out what it actually does, have a look at this thread, which refers back to our pass‑by‑value story.
|
 |
 |
|
|
subject: How to modify method parameters?
|
|
|