In a Kotlin file I try to overload the equals method of the BigDecimal class. I have the following piece of code for that:
fun BigDecimal.equals(n: Any?): Boolean = n is Int && this.compareTo(BigDecimal(n)) == 0
The problem is that this function does not get called by n.equals(1) where n is of type BigDecimal. What's the problem and how can I solve it?
You can not override or shadow functions of classes with extension functions. See the answer to a very similar question here.