Inspectopedia Help

Unnecessary call to 'toString()'

Reports calls to toString() that are used in the following cases:

  • In string concatenations

  • In the java.lang.StringBuilder#append() or java.lang.StringBuffer#append() methods

  • In the methods of java.io.PrintWriter or java.io.PrintStream

  • in the methods org.slf4j.Logger

In these cases, conversion to string will be handled by the underlying library methods, and the explicit call to toString() is not needed.

Example:

System.out.println(this.toString())

After the quick-fix is applied:

System.out.println(this)

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

UnnecessaryToStringCall
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Code style issues

Note that without the toString() call, the code semantics might be different: if the expression is null, then the null string will be used instead of throwing a NullPointerException.

Use the Report only when qualifier is known to be not-null option to avoid warnings for the values that could potentially be null.

Inspection options

Here you can find the description of settings available for the Unnecessary call to 'toString()' inspection, and the reference of their default values.

Report only when qualifier is known to be not-null

Default: Selected

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024