Suppose I have this:
class String2(val x:String) {
def *(times:Int) : String = {
val builder = new StringBuilder()
for( i <- 0 until times) {
builder.append(x)
}
builder.toString()
}
}
now if I add this implicit:
implicit def gimmeString2(y:String) = new String2(y)
I will get a compilation error because stringWrapper also adds this implicit. Is there a way of saying to the compiler "ignore other implicits, use this", so that I don't have to instantiate a String2
object and work on that?
I admit the example code may not be the most appropriate ( for this question ), but I think it will do.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…