Scala implicit region requires double import

I don’t understand why, in the following code, import ( import b._ ), which pulls in implicit def , must appear both at position 1 and at position 2 for it to work.

 package a { abstract class Base {} } package b { import a._ class Derived(i: Int) extends Base {} object b { implicit def i2d(i: Int): Derived = new Derived(i) } } import a._ // position 1 import b._ object test extends App { // position 2 import b._ def doIt(base: Base) { println("works") } doIt(1) } 
+4
source share
1 answer

At position 1, you import everything from package b, and at position 2 you import everything from object b, which includes implicit def. You could just import bb_ at position 2.

+6
source

All Articles