Simão Martins Simão Martins - 4 months ago 37
Scala Question

Are implicits private?

Given the following code:

class Foo[R](i: Int)(implicit ev: Ordering[R]) {
final type T = ev.type

I get the following error:

Error:(13, 16) private value ev escapes its defining scope as part of
type Foo.this.ev.type
type T = ev.type

Which makes me think implicits declared in a constructor are private.
Given that
is final it won't be overridable, so it shouldn't cause any problem. What am I missing here?


All parameters declared in a class constructor are private unless you tell the compiler they are not. This differs from a case class where all parameters in the first argument list are by default public unless you tell the compiler otherwise.

So, yes, unless you specifically add val or some other public-like modifier to the value, it is by default private. Hence, it is telling you that a private member is being made public via the way you are defining that type.