• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to modify method parameters?

 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 76453
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Police line, do not cross. Well, this tiny ad can go through:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic