Reputation: 2341
I have the following snippet of code:
private class SectionConversionMap
extends HashMap[SectionSchema[_], ( Iterable[HtmlRow] ) => Option[Iterable[_]]] {
private type Value[Vt] = ( Iterable[HtmlRow] ) => Option[Iterable[Vt]]
private type SuperKV = (SectionSchema[_], Value[_])
def +[T](kv: (SectionSchema[T], Value[T])):
HashMap[SectionSchema[_], ( Iterable[HtmlRow] ) => Option[Iterable[_]]] = {
super.+(kv: SuperKV)
}
def get[T](key: SectionSchema[T]): Option[Value[T]] = {
super.get(key) match {
case v: Some[Value[T]] => v
case _ => None
}
}
}
The issues is that my IDE says (in the +
method's body, kv: SuperKV
) that
Expression of type (SectionSchema[T], SectionConversionMap.this.Value[T]) does not conform to expected type (SectionSchema[_], SectionConversionMap.this.Value[_])
How is that possible? The second one is more generic.
Upvotes: 0
Views: 38
Reputation: 953
The underscore isn't the equivalent of "?" in Java, although much of the time it can be used in the same way. "_" is for specifying higher-kinded types and that does seem to be, more or less, what you're trying to do here, though I think your code could do with some cleanup of the way types are defined.
Nevertheless, you can make your code compile with the simple expedient of replacing HashMap with Map. Was this an oversight on your part? I can't see any reason why you would want to try to extend HashMap instead of Map (my compiler actually gives a warning about that too).
Upvotes: 1