Tried to make pow
function from BigInteger class available as infix function with the same name. The problem is that now the pow
infix operator calls itself recursively.
Is it possible to make Java function callable using infix operator with same name as function?
package experiments
import java.math.BigInteger
infix fun BigInteger.pow(x: BigInteger): BigInteger {
return this.pow(x);
}
fun main(args : Array<String>) {
val a = BigInteger("2");
val b = BigInteger("3");
println(a + b)
println(a pow b)
}
Causes:
Exception in thread "main" java.lang.StackOverflowError
at kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull(Intrinsics.java:126)
at experiments.KotlinTestKt.pow(KotlinTest.kt)
at experiments.KotlinTestKt.pow(KotlinTest.kt:6)
If I were defining my own Java class (rather than using a library class), is there any way to mark the Java method as infix? Perhaps an annotation?