An implicit class is decomposed into a “normal” class and an implicit method that creates an instance of the class:
implicit class IntOps(i: Int) { def squared = i * i }
Corresponded as
class IntOps(i: Int) { def squared = i * i }
implicit def IntOps(i: Int) = new IntOps(i)
But in Scala, you cannot define a method ( def IntOps) outside an object or class. That's why.
source
share