String
KT-P1002When 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.
val stringValue = Integer(10).toString()
val stringValue = 10.toString()