30 Apr 2012 21:23
Re: so what a (_:String).+ really is (as opposed to (_:String).isEmpty)
In Java, it's built into the compiler and is given special dispensation in the language spec. The language has no support for symbolic method names or for operator overloading; except for Strings which are treated as honorary primitives for this one purpose only (there's also some fun logic involved as regards the formatting of real primitives and calling .toString on objects as part of this concatenation)
In Scala, things are *much* more complicated. We allow symbolic method names, so when "some string" + otherThing is seen, the compiler first looks for the "+" method on strings. As this doesn't exist it then looks for an implicit conversion from Strings to something that *does* have a + method (in this case, it's RichString, which inherits the + method from its StringOps supertype). The String is converted (wrapped) into a RichString, and the method is then invoked.
Scala's approach can be widely used for many more things besides Strings and the + method. It's also just another library feature and isn't baked into the language spec.
On 30 April 2012 19:31, Alec Zorab <aleczorab-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:
Yep.
On 30 April 2012 18:58, Andy Coolware <andy.coolware-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>>
>> the phrase "taken to support" is key here. The string class doesn't
>> have a "+" method on it, the language just pretends it does.
>>
>
> So this is somehow built into a compiler?
Kevin Wright
mail: kevin.wright-4U8lxy6Hl1K35wUkaLeaMEEOCMrvLtNR@public.gmane.org
gtalk / msn : kev.lee.wright-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
vibe / skype: kev.lee.wright
steam: kev_lee_wright
"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra
RSS Feed