1 /*xml 2 <module name="Checker"> 3 <module name="TreeWalker"> 4 <module name="StringLiteralEquality"/> 5 </module> 6 </module> 7 */ 8 package com.puppycrawl.tools.checkstyle.checks.coding.stringliteralequality; 9 10 // xdoc section -- start 11 class Example1 { 12 String getName(){ 13 return "Y"; 14 } 15 void InvalidExample(){ 16 String status = "pending"; 17 // violation below, 'Literal Strings should be compared using equals(), not '=='' 18 if (status == "done") {} 19 // violation below, 'Literal Strings should be compared using equals(), not '!='' 20 while (status != "done") {} 21 // violation below, 'Literal Strings should be compared using equals(), not '=='' 22 boolean flag = (status == "done"); 23 boolean flag1 = (status.equals("done")); 24 String name = "X"; 25 if (name == getName()) {} 26 // OK, limitation that check cannot tell runtime type returned from method call 27 } 28 } 29 // xdoc section -- end