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

Guru

11/11/2021, 5:54 PM
Copy code
fun main() {
    val callback = { i: Int, j: Int ->
        val ii = i.times(j)
        val jj = j.times(ii)
        ii + jj
    }

    println(addAndMultiply(5, 6) { i, j ->
        i + 1 + j
    })

    println(addAndMultiply(5, 6, callback))
}

inline fun <T> addAndMultiply(x: T, y: T, call: (T, T) -> T): T where T : Number {
    if (x is BigDecimal || x is BigInteger) return call(x, y)
    if (y is BigDecimal || y is BigInteger) return call(x, y)

    return call(x, y) * x * y
}
I am getting reciever type mismatch at
return call(x, y) * x * y
Any Idea ?
l

Luke

11/11/2021, 6:19 PM
I don't think the multiplication, or any arithmetic operator, is defined for Number
👆 2
2 Views