🔴 Scala Beginner

What is implicit in Scala?

Answer

Implicits in Scala (Scala 2) allow the compiler to automatically provide values, conversions, or parameters. Implicit parameters: def greet(name: String)(implicit lang: Language) — the compiler finds a matching implicit val in scope. Implicit conversions: automatically convert a type to another: implicit def intToString(i: Int): String = i.toString. Extension methods via implicit classes: implicit class RichInt(n: Int) { def doubled = n * 2 }; 5.doubled // 10. Implicits power Scala's type class pattern for ad-hoc polymorphism. They were powerful but criticized for being hard to understand and debug. Scala 3 (Dotty) replaced implicits with clearer constructs: given/using for implicit parameters and extension methods. Understanding implicits is essential for reading Scala 2 code and popular libraries like Cats and Akka.