Is there a way to configure eclipse to tag an == comparison on String objects as Errors? I just want a way to prevent developers from using == to compare strings accidentally or unknowingly. I searched through eclipse and could not find anything. Any ideas.
There is nothing built into Eclipse that you can enable to do this check, afaik. But, you can incorporate a third party static analysis tool to do it for you. FindBugs does have a rule to check for exactly what you've described, and can be incorporated into Eclipse via plugin.
Other static analysis tools you might want to take a look at include Checkstyle and PMD.
Use PMD or Findbugs plugins for eclipse to do this. These tools will also let you catch other common programming mistakes.
Direct link to findbug rule to detect this situation: http://findbugs.sourceforge.net/bugDescriptions.html#ES_COMPARING_STRINGS_WITH_EQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With