Unambiguous Subimplicits

寵の児 提交于 2019-12-05 10:32:13

Note: I'm probably vastly oversimplying things, but in testing it seemed like the following.

It's because the 2nd one is in an inner scope, so it has precedence. Its the same thing that happens with

object test {
 val a = 5
 def test(i: Int) = {
   val a  = 6
   i + a
 }
}

In this case you would expect a to be 6 inside the function. The following is similar.

object test {
  implicit val i = 5; 
  { 
    implicit val b = 6; 
    test
  } 
  def test(implicit ii:Int) = println(ii)
} 

Updated from comment.

scala> def test(a: Int) = {val a = 5; a }
test: (a: Int)Int

scala> test(6)
res1: Int = 5
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!