Tuesday, 26 April 2016

Scala implicit Precedence

While scala compiler look for implicit, takes following precedence

1) First look in current scope

    implicit val n: Int = 4
    def add(x: Int)(implicit y: Int) = x+y 


2) Looks into import
3) Looks into wildcard  import
4) Find in companion Object

If found two matching implicit in above scope compiler will give error.

No comments:

Post a Comment