Quick stupid question... trying to learn Kotlin by...
# announcements
m
Quick stupid question... trying to learn Kotlin by coding some codewars challenges, and how to convert mutableListOf("abc", "def", "ghi").map { it.length } to an Array<Int>?
u
mutableListOf("abc", "def", "ghi").map { it.length }.toTypedArray()
if I remember correctly
m
so if I do someString.split(" ").map { it.length!! }.toTypedArray<Int>().min(), I am seeing
inferred type is Int? but Int was expected
.
s
Uglijesa’s answer is correct, the “problem” is that
min()
returns null in case you are working with an empty array. That’s true whether you are working with Array<Int> or Array<Foo>
m
Ah! I see, the ^ error marker is pointing at toTypedArray so I am confused.
Thanks all!
👍 2