October 2018
Intermediate to advanced
370 pages
9h 15m
English
This function takes one parameter: a minimum value. It returns the target value if it is greater than or equal to minValue, otherwise it returns minValue. The coerceAtLeast function makes sure that the returned value is at least as great as the value that is mentioned in minValue:
val i = 2.coerceAtLeast(4)println(i)
Here, the answer will be 4, because minValue is greater than the target value, 2.
Read now
Unlock full access