Kotlin

Kotlin

Made by DeepSource

Creation of temporary objects when converting primitive types to String KT-P1002

Performance
Minor

When converting primitive types to String, you should avoid creating an object of the respective primitive type first and then using .toString() for converting it to a string. Creating a temporary object is an unnecessary overhead and can incur a performance penalty.

Instead, you can directly call toString() on the value (even if it is a literal).

It's worth noting that this guideline is especially relevant for performance-sensitive scenarios. In general cases where performance is not a critical concern, the impact of temporary object creation is negligible.

Bad Practice

val stringValue = Integer(10).toString()

Recommended

val stringValue = 10.toString()