In the following code snippet (using scala 2.10.3) TestClass1 does not compile with error "value toInt is not a member of String" but TestClass2 compiles fine:
trait TestTrait {
implicit def test: (String => Int)
}
object TestClass1 extends TestTrait {
implicit val test = (value: String) => value.toInt
}
object TestClass2 extends TestTrait {
implicit def test = (value: String) => value.toInt
}
The StringOps implicit conversion via augmentString(), which provides the toInt function, is not applied in TestClass1 but is applied fine in TestClass2. Can somebody tell me why this is the case and how to keep test a val instead of a def?
value
was a member of your TestClass1 object, you could make it work :object TestClass1 (value:String) { implicit val test => value.toInt }
but that's probably not what you had in mind? – Ashalynd