I had some code:
def sum1(x: Int)(y: Int) = x + y
and
def sum2(x: Int)(implicit y:Int) = x + y
Could you please explain for me which case will use sum1 and sum2?
Thank you!
I had some code:
def sum1(x: Int)(y: Int) = x + y
and
def sum2(x: Int)(implicit y:Int) = x + y
Could you please explain for me which case will use sum1 and sum2?
Thank you!
In order to call a function with an implicit parameter, exactly one value with a type matching the implicit parameter must exist in the implicit scope.
Here are some very easy examples:
As you may understand from the examples, implicit resolution is done at compile time.
To know more on the topic (and to have some more interesting and meaningful examples) I suggest reading this page of the Scala documentation.