Saturday, June 30, 2012

Name Shadowing and Conflicts – better Eclipse Settings


Today I fought a nasty bug that was caused when I accidentally declared a Class method local variable with the same name as a Class level variable.  Eclipse 3.5.2 in its stock configuration ignores this kind of a name shadowing/conflict.  Fortunately there’s an IDE setting that you can use to have these kinds of errors flagged.  Go to the following location in the IDE:
Eclipse -> Preferences -> Java -> Compiler -> Errors/Warnings -> Name shadowing and conflicts
And set Field declaration hides another field or variable and Local variable declaration hides another field or variable to Error or Warning, whichever you prefer.  Here’s the StackOverflow question I asked that got me that solution.

No comments:

Post a Comment