KT.UNNECESSARY_TEMPORARY_INSTANTIATION

Temporary objects when converting primitive types to String

Avoid temporary objects when converting primitive types to String. This has a performance penalty when compared to using primitive types directly. To solve this issue, remove the wrapping type.

Noncompliant Code

Copy
val i = Integer(1).toString() // temporary Integer instantiation just for the conversion

Compliant Code

Copy
val i = Integer.toString(1)

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html