Implicit conversions

The first type of implicit in our list is implicit conversion. They allow you automatically to convert values of one type into values of another type. This implicit conversion is defined as a one-argument method that's marked with the implicit keyword. Implicit conversions are considered to be a somewhat controversial language feature (we will take a look at why in a moment), so we need to enable them explicitly with a compiler flag or by importing the corresponding language feature:

import scala.language.implicitConversions

Predef contains a number of implicit conversions for Java-specific classes and primitives. For example, this is how autoboxing and autounboxing is defined for Scala's Int and Java's Integer:

// part ...

Get Learn Scala Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.