Redundant toString on String

ID

java.string_redundant_tostring

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Java

Tags

code-style

Description

Reports calls to toString() on expressions that are already of type java.lang.String. The call is redundant and adds noise to the code.

Rationale

Calling toString() on a String is a no-op that returns the same object. It obscures intent and suggests the author was unsure of the variable’s type.

// Bad — redundant call
String name = getName();
String copy = name.toString();

Remediation

Remove the unnecessary toString() call.

// Good — use the String directly
String name = getName();
String copy = name;