I would like to add an implicit parameter to a class with a private constructor. Here as a simplified example:
class A[T] private(a:Int){
def this()=this(0)
}
If I would like to apply Pimp my library pattern to T with Ordered[T], I would need to use (the deprecated) view bound like so:
class A[T <% Ordered[T]] private(a:Int){
def this()=this(0)
}
And this works. However, to avoid the deprecated syntactic sugar I would like to pass the implicit parameter to the class. Unfortunately, this is where I'm probably doing something wrong:
class A[T] private(a:Int)(implicit conv:T=>Ordered[T]){
def this()=this(0)
}
For the above code, the compiler generates the following error:
error: No implicit view available from T => Ordered[T].
def this()=this(0)
While if I try to pass the implicit parameter directly like so:
class A[T] private(a:Int)(implicit conv:T=>Ordered[T]){
def this()=this(0)(conv)
}
I get this:
error: not found: value conv
def this()=this(0)(conv)
How does one pass an implicit parameter in this case?
EDIT: After some more experimentation it seems that redefining the constructor with implicit parameter is the problem. Not the fact that the constructor is private.