Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type inference failed. The value of the type parameter T should be mentioned in input types in when block

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
    }
}
} 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading