scalaimplicit-parameters

How to extend class with implicit parameter in Scala


class B(implicit imp: Int) extends AC { }

object C extends B{

}

Error: could not find implicit value for parameter imp

This is what i was looking for: How to provide default value for implicit parameters at class level


Solution

  • scala> class B(implicit imp:Int)
    defined class B
    
    scala> class C extends B()(1)
    defined class C
    
    scala> implicit val imp:Int = 2
    imp: Int = 2
    
    scala> class D extends B
    defined class D
    
    scala>