Scala traits and implicit conversion confusion

Posted by pr1001 on Stack Overflow See other posts from Stack Overflow or by pr1001
Published on 2010-04-17T22:12:11Z Indexed on 2010/04/17 22:43 UTC
Read the original article Hit count: 289

Filed under:
|
|

The following lines work when I enter them by hand on the Scala REPL (2.7.7):

trait myTrait {
  override def toString = "something"
}
implicit def myTraitToString(input: myTrait): String = input.toString
object myObject extends myTrait
val s: String = myObject

However, if I try to compile file with it I get the following error:

[error] myTrait.scala:37: expected start of definition
[error] implicit def myTraitToString(input: myTrait): String = input.toString
[error]          ^

Why?

Thanks!

© Stack Overflow or respective owner

Related posts about scala

Related posts about traits