原文出处 http://alvinalexander.com/scala/scala-implicit-method-arguments-fields-example
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
C:\Users\Bo>scala
Welcome to Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_71).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def yo(implicit s: String) = println("Yo, "+ s)
yo: (implicit s: String)Unit
scala> yo("Adrian")
Yo, Adrian
scala> implicit val fred = "Fred"
fred: String = Fred
scala> yo
Yo, Fred
scala> implict val one = 1
<console>:1: error: ‘;‘ expected but ‘val‘ found.
implict val one = 1
^
scala> implicit val one = 1
one: Int = 1
scala> yo
Yo, Fred
scala> implicit val barney = "Barney"
barney: String = Barney
scala> yo
<console>:12: error: ambiguous implicit values:
both value fred of type => String
and value barney of type => String
match expected type String
yo
^
scala>
希望你能中明白,隐式参数和隐式field是怎么一起协调使用的。