As far as I understand, implicit conversions can result in potentially hard to understand code, or code suffering from other problems (perhaps even bugs?), which is why they require explicit enabling in order to be used in code without getting warnings.
However, given that implicit conversions are in big part (if not most of the time) used for wrapping an object with an object of another type, and so are implicit classes—I'd appreciate you correcting me if I'm wrong—, why do the former require the import of scala.language.implicitConversions
but the latter do not?
object Main extends App {
implicit class StringFoo(x: String) {
def fooWithImplicitClass(): Unit =
println("foo with implicit class")
}
// => silence.
"asd".fooWithImplicitClass()
/************************/
class Foo(x: String) {
def fooWithImplicitDef(): Unit =
println("foo with implicit def")
}
implicit def string2Foo(x: String) = new Foo(x)
// => warning: implicit conversion method string2Foo should be enabled
"asd".fooWithImplicitDef()
}