I write the following implicit conversion in scala:
implicit def strToInt2(str: String):Int = {
str.toInt
}
But it rises this compilation error:
<console>:9: error: type mismatch;
found : str.type (with underlying type String)
required: ?{val toInt: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method augmentString in object Predef of type (x: String)scala.collection.
immutable.StringOps
and method toi in object $iw of type (str: String)Int
are possible conversion functions from str.type to ?{val toInt: ?}
str.toInt
^
If I remove the return type, just declare it like this:
implicit def strToInt2(str: String) = {
str.toInt
}
It compiles successfully. Can anyone tell me what's the difference between the two ?