• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to modify method parameters?

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10090
55
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chaitanya, Winston gave you that link for a reason. Is it really too much trouble click the link and go through that page?
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic