fun Double.isInRange(val lower: Double, val upper: Double) { return this >= lower && this <= upper }
fun Float.isInRange(val lower: Double, val upper: Double) { return this >= lower && this <= upper}
fun Int.isInRange(val lower: Double, val upper: Double) { return this >= lower && this <= upper}
fun Long.isInRange(val lower: Double, val upper: Double) { return this >= lower && this <= upper}
I looked at using Number as the base class but I dont quite grasp how covariance works in generics in Kotlin (also Number itself isn’t comperable so I was casting everything to a Double - this.toDouble() which doesn’t seem to sit right with me.)
Yes, you've got the reason right. Exception is caused with the same signatures in bytecode for "isInRange" functions. And they are same becuase of java type erasure mechanism.
Currently we have no good workaround for this problem and that’s why such declarations are forbidden.
(Of course some tricks with writing different signatures to bytecode could be done but such auto rewriting can make kotlin code too unstable to binary compatibity issues).