I have the following case class:
case class Alert[T <: Transport](destination: Destination[T], message: Message[T])
In Scala 2.9.2, the following method signature has compiled fine:
def send(notification: Alert[_]) {
notification match {
...
}
}
Now in Scala 2.10.1 it fails to compile with the following error:
type arguments [_$1] do not conform to class Alert's type parameter bounds [T <: code.notifications.Transport]
Why is this? How can I fix the error? Simply giving the same type bounds to send
results in a lot more compile errors...
Update: Looking at SIP-18, I don't think the reason is that I don't have existential types enabled, as SIP-18 says it's only needed for non-wildcard types, which is exactly what I do have here.
There error seems to be saying that the existential type "_
" is not constrained to be a subtype of Transport
. This may be the preferred solution,
trait Transport
trait Destination[T]
trait Message[T]
case class Alert[T <: Transport](destination: Destination[T], message: Message[T])
def send[T <: Transport](notification: Alert[T]) {
notification match {
case _ => ()
}
}
This also seems to work,
def send(notification: Alert[_ <: Transport])
but I think it's preferable not to use existential types.