function min in Kotlin

Viewed 2130

i use the Mathematical function "min" in my Kotlin code to declare a variable "toRemove"

val toRemove = min(preferredQuantity - taken, stock.quantity) 

error message : Kotlin unresolved reference

1/ may i know how could i solve it?

2/ the function is within kotlin.math, why I cannot use it directly? https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.math/

Thanks!

1 Answers

For completeness' sake: as pointed out by @Tenfour04 in the comments, make sure that kotlin.math.min is imported by checking that one of

import kotlin.math.min
import kotlin.math.*

is on top of the file. The kotlin.math.* variant will import everything from the kotlin.math package. See the Kotlin documentation page on imports.

Related