O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implicit Type Conversions

The compile-time type checking is quite rigorous in Scala. If you don’t pass the type expected by a function or invoke an arbitrary method on an instance, you’ll get a stern error at compile time. While this is good most of the time, occasionally you’d want to pass an instance of one type where another type is expected—mainly where such use will make code intuitive, more expressive, and easy to write. Likewise, you may want to invoke your own domain-specific convenient methods on third-party classes. This can give an illusion of greater power to open and add methods to existing third-party classes. All this is possible in Scala with just a few tricks by using type conversions.

There are two different ways to implement ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required