Class StringLiteralEqualityCheck

All Implemented Interfaces:
Configurable, Contextualizable

Checks that string literals are not used with == or !=. Since == will compare the object references, not the actual value of the strings, String.equals() should be used. More information can be found in this article.

Rationale: Novice Java programmers often use code like:

 if (x == "something")
 

when they mean

 if ("something".equals(x))
 

Parent is com.puppycrawl.tools.checkstyle.TreeWalker

Violation Message Keys:

  • string.literal.equality
Since:
3.2