Why does this explicit call of a Scala method allow it to be implicitly resolved?

Posted by Matt R on Stack Overflow See other posts from Stack Overflow or by Matt R
Published on 2010-04-28T16:07:02Z Indexed on 2010/04/28 16:23 UTC
Read the original article Hit count: 297

Filed under:
|
|

Why does this code fail to compile, but compiles successfully when I uncomment the indicated line? (I'm using Scala 2.8 nightly). It seems that explicitly calling string2Wrapper allows it to be used implicitly from that point on.

class A {
  import Implicits.string2Wrapper
  def foo() {
     //string2Wrapper("A") ==> "B" // <-- uncomment
  } 
  def bar() {
    "A" ==> "B"
    "B" ==> "C"
    "C" ==> "D"
  }
  object Implicits {
    implicit def string2Wrapper(s: String) = new Wrapper(s)
    class Wrapper(s: String) {
      def ==>(s2: String) {}
    }
  }
}

© Stack Overflow or respective owner

Related posts about scala

Related posts about scala-2.8