I am new to Scala and trying to learn and understand implicit conversions and parameters and came across a script that I find confusing.
For context, I use Scaldi to inject dependencies in an Akka application and would like multiple injection entities to inherit from an abstract class. I believe that I cannot make an abstract class a trait precisely because we need to make an implicit Injector accessible through the constructor argument in order to use the framework.
A very contrived example demonstrating the behavior that I see is as follows:
class SecretSauce {} abstract class Base(implicit secretSauce: SecretSauce) {} class Concrete extends Base {} object Example extends App { ... // Setup Actor system, etc, etc implicit val secretSauce: SecretSauce = new SecretSauce() }
I expected everything to work, but instead I get a compilation error:
Unspecified value parameter secretSauce. class Concrete extends Base { ^
If I add an implicit parameter to a specific class, for example, everything will work:
class Concrete(implicit secretSauce: SecretSauce) extends Base {}
I think my confusion stems from the way implicit parameters work - in situations like the description, are they not inherited by child classes? Can someone ELI5 what is happening in my example, or point me to a link that can help clarify the situation?
Thanks!
source share