Possible Duplicate:
How to unimport String “+” operator in Scala?
So things from Predef get automatically imported into scala programs. But how can I disable- unimport certain or all imported functions from Predef? As an example if I don't like the '+' operator on String how to disable this functionality?
As mentioned in the linked answer, the method
String#+(other: Any)
is added to the String class with compiler magic, rather than with an implicit conversion. As such, it isn't related to the automatic import ofPredef._
.The same applies to
Int#+(x: String)
, and corresponding method on the other value types.However, there is another String concatenation method that is added by an implicit conversion in
Predef
.x + "2"
is treated asPredef.any2stringAdd(x).+("2")
. By explicitly importingPredef
on the first line of your file, you can rename unwanted members to_
, disabling them.I don't think that this works in Scala Scripts or in the REPL. There is also an unsupported option,
-Yno-predef
, to turn of the automatic import globally.Related: SI-1931