July 2017
Intermediate to advanced
796 pages
18h 55m
English
We have addressed implicits in the previous chapters, but here we are going to see more examples. Implicit parameters are very similar to default parameters but they use different mechanisms in order to find the default value.
An implicit parameter is one that is passed to a constructor or a method and is marked as implicit, which means that the compiler will search for an implicit value within the scope if you don't provide a value for this parameter. For example:
scala> def func(implicit x:Int) = print(x) func: (implicit x: Int)Unitscala> func<console>:9: error: could not find implicit value for parameter x: Int func ^scala> implicit val defVal = 2defVal: Int = 2scala> func(3)3
Implicits are very useful for the collection ...
Read now
Unlock full access