How to override a implicit function of companion object?

270 views Asked by At

I am new to Scala and implicit conversions.

I am working with an existing scala library over which I have no control. Lets consider a class R from the library.

abstract class R {

}

object R {
    implicit def RFunctions[K, V](r: R[(K, V)]) (implicit kt: ClassTag[K],vt: ClassTag[V], ord: Ordering[K] = null): RFunctions[K, V] = { new RFunctions(r) }
}

I am extending the class R to override almost all of its behavior. But this new class is a Java class. Let's call this A.

class A extends R {

}

Problem is, at some point in my control flow, the control jumps to the implicit declaration for R and ends up using RFunctions class for any functionality.

The methods which are present in RFunctions are also implemented in my extended class A. I do not understand how I can bypass or avoid the implicit conversion.

Any ideas would be appreciated.

1

There are 1 answers

0
John K On

Extend abstract class R with abstract class Rbis in Scala, and in companion object Rbis define the implicit functions you need (they will be called before the ones in R in our case), then in java you extend Rbis.