Re: so what a (_:String).+ really is (as opposed to (_:String).isEmpty)
implicit def any2stringadd(x: Any) = new runtime.StringAdd(x)
and then runtime.StringAdd is basically a wrapper for String.valueOf(x)
interestingly enough though, when you then actually look at the
bytecode (I didn't know you could do that on the console, it's
incredibly convenient), you'll see absolutely no trace of the
StringAdd thing anywhere. I'm not sure whether this means that the
StringAdd thing is a red herring, and the whole process is actually
special cased by the compiler, or whether the compiler is smart enough
to elide the unneeded implicit in this case. I suspect the former
On 1 May 2012 07:59, Andy Coolware <andy.coolware@...> wrote:
> Thanks for all the answers good and not so good :-P.
> so we covered "text"+5 where apparently the build in operation (_:String).+(
> is being employed via StringBuilder.
> Now what really happen, purely from Scala language semantics if we write
> 5+"text". There is really no (_:Int).+ applicable here. What happens here?
> I also noticed that if defined implicit conversion String=>Int is not really
> involved even if it is available in the scope.