Hi,
Any reason why array doesn’t have a nice toString method, just like List?
fun main(args: Array<String>) {
println(listOf(1,2,3))
println(arrayOf(1,2,3))
}
output:
[1, 2, 3]
[Ljava.lang.Integer;@36b29562
Hi,
Any reason why array doesn’t have a nice toString method, just like List?
fun main(args: Array<String>) {
println(listOf(1,2,3))
println(arrayOf(1,2,3))
}
output:
[1, 2, 3]
[Ljava.lang.Integer;@36b29562
The implementation of both of these toString() methods is provided by the JVM; Kotlin has no influence on that.
For arrays you can use contentToString() extension function which replicates List.toString functionality.
Can they be overridden in Kotlin std-lib?
No, they can’t.