Typo in toString¶
ID: java/tostring-typoKind: problemSecurity severity: Severity: warningPrecision: mediumTags: - quality - reliability - correctness - readabilityQuery suites: - java-security-and-quality.qls
Click to see the query in the CodeQL repository
A method namedtostring may be a typographical error.toString (different capitalization) may have been intended instead.
Recommendation¶
Ensure that any such method is intended to have this name. Even if it is, it may be better to rename it to avoid confusion with the inherited methodObject.toString.
Example¶
The following example shows a method namedtostring. It may be better to rename it.
publicclassCustomer{privateStringtitle;privateStringforename;privateStringsurname;// ...publicStringtostring(){// The method is named 'tostring'.returntitle+" "+forename+" "+surname;}}
References¶
Java API Specification: Object.toString.