Let’s say I have this trait
trait Ctx[C, V[_]]
I am unable to construct any method signature that takes a Ctx of which the second type parameter is unspecified (wildcard). E.g. this:
def test(c: Ctx[_, _]) = ()
doesn’t compile ("error: _$2 takes no type parameters, expected: one"). Neither can I do
def test(c: Ctx[_, _[_]]) = ()
("error: _$2 does not take type parameters"). What am I missing?
I’m able to define this one:
And it seems to work ok with type inference:
Edit: I suspect it won’t be practical to replace
Ctxto use an abstract type, but this is what I was able to do:Using an abstract type for V spares you the complicated (or impossible) task of figuring the type parameter syntax for a wildcard type constructor. Additionally as demonstrated in the ListBuffer example you can then handle objects where the
Vis a different type constructor (Option and List in my example). The first solution I provided would not allow you to do that.Edit 2: How about?