Scala Language Implicits

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.


Got any Scala Language Question?