Is it possible to add a new static method to the java.lang.Math
class in Kotlin
? Usually, such things are possible in Kotlin thanks to Kotlin Extensions.
I already tried doing the following in a file I made called Extensions.kt
:
fun Math.Companion.clamp(value:Double,minValue:Double,maxValue:Double):Double
{
return Math.max(Math.min(value,maxValue),minValue)
}
but Math.Companion
could not be resolved...
fun Double.clamp(min: Double, max Double)
, to be called like1.0.clamp(2.0, 3.0)
. – Marbut