Given the following in Java:
public interface Reply<T> {
T data();
}
public class StatusReply implements Reply<String> {
private final String status;
public StatusReply(String status) {
this.status = status;
}
@Override
public String data() {
return status;
}
}
I want to be able to do this in Scala:
class PassthroughReply[R <: Reply[_]](val reply: R)
extends Reply[T] { // won't compile, `T` type not found
override
def data[T : Reply]: T = reply.data
}
val statusReply = new StatusReply("OK")
val passthroughReply = new PassthroughReply[SatusReply](statusReply)
passthroughReply.data // Should return "OK"
What I want is that the data
in an instance of PassthroughReply
, should have the same type as the data
of its wrapped sub type of Reply
.