Scala LanguageImplicits


Syntax

  • implicit val x: T = ???

Remarks

Implicit classes allow custom methods to be added to existing types, without having to modify their code, thereby enriching types without needing control of the code.

Using implicit types to enrich an existing class is often referred to as an 'enrich my library' pattern.

Restrictions on Implicit Classes

  1. Implicit classes may only exist within another class, object, or trait.
  2. Implicit classes may only have one non-implicit primary constructor parameter.
  3. There may not be another object, class, trait, or class member definition within the same scope that has the same name as the implicit class.