Text of codeql.github.com › codeql-query-help › java › java-useless-tostring-call as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

Useless toString on String — CodeQL query help documentation

CodeQL query help documentation » CodeQL query help for Java and Kotlin » Useless toString on String ¶ ID: java/useless-tostring-call Kind: problem Security severity: Severity: recommendation Precision: high Tags: - quality - maintainability - useless-code Query suites: - java-code-quality.qls - java-security-and-quality.qls Click to see the query in the CodeQL repository There is no need to call toString on a String because it just returns the object itself.

From the Java API Specification entry for String.toString() : public String toString() This object (which is already a string!) is itself returned. Recommendation ¶ Do not call toString on a String object. Example ¶ The following example shows an unnecessary call to toString on the string name . public static void main ( String args [] ) { String name = "John Doe" ; // BAD: Unnecessary call to 'toString' on 'name' System . out . println ( "Hi, my name is " + name . toString ()); // GOOD: No call to 'toString' on 'name' System . out . println ( "Hi, my name is " + name ); } References ¶ Java API Specification: String.toString() . © GitHub, Inc.

Terms Privacy