I get this error in android studio "Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly. :349 , :350 "
It’s nearly 2 days that i can’t fix it
And here is my code snippet 346:353
private fun scoreOfRate(rate: Double): Double {
return when {
rate <= 100 -> (rate / 100) * 50
rate in 101..120 -> 100.0
rate in 121..160 -> 100 - (mapValue((rate - 120).toFloat(), 1.toFloat(), 160.toFloat(), 0.toFloat(), 100.toFloat()).toDouble()) * 1.0
else -> 0.0
}
}
fun mapValue(value: Float, fromLow: Float, fromHigh: Float, toLow: Float, toHigh: Float): Float {
return (value - fromLow) / (fromHigh - fromLow) * (toHigh - toLow) + toLow
}
(It’s in kotlin)
I asked about it from copilot gemini chatgpt but non of them could solve it.
I used every technique from other posts
>Solution :
This is working , mentioned the data type in the input params like this rate in (121f..160f)
private fun scoreOfRate(rate: Double): Double {
return when {
rate <= 100 -> {
(rate / 100) * 50
}
rate in (101f..121f) -> {
100.0
}
rate in 121f..160f -> {
100 - (mapValue((rate - 120).toFloat(), 1.toFloat(), 160.toFloat(), 0.toFloat(), 100.toFloat()).toDouble()) * 1.0
}
else -> {
0.0
}
}
}