It's close:
object ABlock { class A object A { implicit def strToA(s: String): A =
Or, if you put everything on one line:
class A; object A { implicit def strToA(s: String): A =
... although in any case, you still have to import the implicit conversion to do the following work on your request:
import ABlock.A.strToA // for the form with the enclosing object import A.strToA // for the one-line form without an enclosing object val v: A = "apple"
The reason you need to do this is because every line that you enter in the REPL is enclosed in an object, and each subsequent line is nested in the previous one. This is done so that you can do the following things without getting override errors:
val a = 5 val a = "five"
(In fact, the second definition of a here is the shadow of the first.)
source share