我正在尝试在scala中创建一个提供程序类,它将在调用时返回正确的对象
性状
trait RemoteValidator[A <:Widget]{
def processRemoteValidation(request: EventRequest[_], widget: A): Future[Seq[Widget]]
}
类扩展特性
class ResourceInstanceListRemoteValidator @Inject() extends RemoteValidator[InstanceListWidget[InstanceWidget]] {
override def processRemoteValidation(request: EventRequest[_], widget: InstanceListWidget[InstanceWidget]): Future[Seq[Widget]] = {
//stuff
}
提供商
class RemoteValidatorProvider[T] @Inject()(resourceInstanceListRemoteValidator: ResourceInstanceListRemoteValidator) {
val validators = Map("resources" -> resourceInstanceListRemoteValidator)
def getRemoteValidator(key: String): Option[RemoteValidator] = {
validators.get(key)
}
}
issuse是当我调用provider.processRemoteValidation(request,instanceListWidget)时,我得到&#34;类型不匹配期望类型A,实际InstanceListWidget [InstanceWidget]。我知道这可以在java中工作,但是我不太熟悉scala中的泛型,我该怎么做呢?