You are previewing Scala in Depth.

Scala in Depth

Cover of Scala in Depth by Foreword by: Martin Odersky... Published by Manning Publications
O'Reilly logo

Chapter 5. Using implicits to write expressive code

 

In this chapter
  • Introduction to implicits
  • Mechanics of the implicit resolution system
  • Using implicits to enhance classes
  • Using implicits to enforce scope rules

 

The implicit system in Scala allows the compiler to adjust code using a well-defined lookup mechanism. A programmer in Scala can leave out information that the compiler will attempt to infer at compile time. The Scala compiler can infer one of two situations:

  • A method call or constructor with a missing parameter.
  • Missing conversion from one type to another type. This also applies to method calls on an object that would require a conversion.

In both of these situations, the compiler follows a set of rules to resolve missing data ...

The best content for your career. Discover unlimited learning on demand for around $1/day.