The coerceAtMost(maxValue) function

This function takes one parameter: a maximum value. The function returns the target value if it is less than or equal to maxValue, otherwise it returns the maxValue. The coerceAtMost function makes sure that the returned value is not more than maxValue:

val i = 2.coerceAtMost(4)
println(i)

Here, the answer will be 2, because the target value of 2 is less than maxValue, which is 4

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179