Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkstyle and hidden field?

 
keith doyle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running checkstyle and its complaining that a local variable "hides a field."
The checkstyle API says:
"Checks that a local variable or a parameter does not shadow a field that is defined in the same class."

I don't understand this - what is a field? Can someone give me a simple example of this problem.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't use checkstyle at the moment but I guess the following is happening


The second index is hiding the first one. Which can be confusing at times.
 
keith doyle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I figured it out basically checkStyle doesn't like the parameter name to be the same name as the local variable in a setter method. i.e.



Personally, I like this approch, you can disable this check in sun_checks.xml using the following :
 
keith doyle
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bart!
FYI - I tested for the condition you explained and this will also create the complaint.
Happy Days...
Keith.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to IDEs and other tools.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic