https://kotlinlang.org logo
#getting-started
Title
# getting-started
w

Wavecycle

09/23/2020, 2:24 PM
I'm having some trouble with a warning with my code "Type inference failed. The value of the type parameter K should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly." I've seen a few of the posts asking this question where people were generally using generics, but I'm not using them here. The code runs fine on 1.4 but wasn't running on codewars where they' running 1.3. Help is appreciated thank you
class Leetspeak : Encoder() {
private val leetChars = mapOf<String, String>("a" to "4", "e" to "3", "l" to "1",
"m" to "/^^\\", "o" to "0", "u" to "(_)")
override fun encode(source: String?): String {
return if (source.isNullOrEmpty()) ""
else source.map { it: Char ->  leetChars.get(it) ?: it.toString() }
.joinToString("")
}
}
d

diesieben07

09/23/2020, 2:26 PM
You are calling
leetChars.get
with a
Char
. But the map keys are
String
. The
get
will never return anything
👍 2
w

Wavecycle

09/23/2020, 2:27 PM
Doh, thanks for that, it looks so obvious now 🙂
9 Views