Created
May 5, 2013 10:03
-
-
Save danhper/5520374 to your computer and use it in GitHub Desktop.
Scala implicit method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Foo { | |
implicit def foo(): Unit = println("foo") | |
def bar(implicit f: () => Unit) = f() | |
} | |
object Main { | |
def main(args: Array[String]): Unit = { | |
Foo.bar | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
なるほど、メソッドが定義するスコープにあっても呼び出すスコープにそれをインポートしないとダメということですね。http://www.scala-lang.org/node/114の例だと定義してるスコープと呼び出してるスコープが同じだったので、混乱しちゃいました。
ありがとうございます!