I'm writing a DSL where the "+" operator is strictly numeric, like some other popular languages. It's close, but the String "+" operator is messing up my implicit conversions. What's the syntax for unimporting an operator of the String class?
Just to be clearer, instead of this:
scala> var x = "2" + 3; x: java.lang.String = 23
I'd like to get x: Int = 5
I imagine I just need 2 things to make that happen:
- Remove (unimport within my scope) the definition of "+" from Strings
- Define an implicit conversion of String to Int
I'm stuck on the first step.
Thanks
any2stringadd
is used where the left hand side doesn't support the+
operator, but the right hand side is a string. (To see this in action, runscala -Xprint:typer
and executenew Object + "ZZZZZ"
) By contrast,"ZZZZZ" + new Object
can use the + operator that's already defined onString
, soany2stringadd
is not used. – Arcboutant