toString()
used in string concatenations and as arguments to the
print()
and println()
methods of java.io.PrintWriter
and java.io.PrintStream
, the append()
method of java.lang.StringBuilder
and java.lang.StringBuffer
or the trace()
, debug()
, info()
,
warn()
and error()
methods of org.slf4j.Logger
. In these cases the conversion
to string will be handled by the underlying library methods and an explicit call to toString()
is no needed.
Note that without the toString()
call the code semantics might be different: if the expression is null
then the string null
will be used instead of throwing a NullPointerException
. Use the checkbox
to avoid warnings for the values that could potentially be null.