I have a scenario that is causing a type mismatch that I cannot seem to resolve. Here's a simplified version of the code:
abstract class Msg
trait Channel[M <: Msg] {
def receive(): M
def ack(envelope: M)
}
object ChannelSender {
private var channel : Channel[_ <: Msg] = _
def assignChannel(channel : Channel[_ <: Msg]) = this.channel = channel
def test() {
val msg = channel.receive()
channel.ack(msg) // Type mismatch here
}
}
The error from the compiler is:
type mismatch; found : msg.type (with underlying type com.msgtest.Envelope) required: _$1 where type _$1 <: com.msgtest.Envelope
What sort of changes could I make to get this working? Additionally, the changes require that the following concrete implementation compile:
class SomeMsg extends Msg
object SomeChannel extends Channel[SomeMsg] {
def receive(): SomeMsg = { null.asInstanceOf[SomeMsg] }
def ack(envelope: SomeMsg) {}
}
object Setup {
ChannelSender.assignChannel(SomeChannel)
}