Functional Programming, from Java to Scala, D. Wall
artima.com
artima.com
implicit def string2regexTest(s:String)=new RegexTest(s)
//Now we can just do
someString @= /regularExpression/
which lets you use @= as you use ~= in Ruby.This looks sort of evil à la monkey-patching, but it isn't nearly as bad as the compiler will complain if more than one implicit ever matches, which prevents the situation where something is redefined under you. This is definitely a good thing Scala has going for it that Ruby doesn't.
Open classes let you add features at runtime. [snip] It's
the kind of thing that would be driving programmers nuts by
the end of a 20-year maintenance cycle. But it's a godsend
when the developers of the original library weren't prescient
enough (or didn't have the time) to develop everything you
need.
This is what implicit conversions are for: