我對斯卡拉相對較新,我遇到了泛型類型參數的問題。我執行某些操作的命令模式,我有一個基類是這樣的:斯卡拉通用類型參數問題
abstract class Command[A, B <: BaseModel, T[X] <: CommandResponseWrapper[X] forSome { type X }](repository: BaseRepository[A, B], entity: B) {
@throws(classOf[Exception])
def execute: Future[T[X] forSome { type X }]
}
現在,藉此具體命令爲我有問題的樣本:
case class AgentExecutionListCommand(repository: AgentExecutionRepository[Int, AgentExecution], entity: AgentExecution)(implicit ec: ExecutionContext) extends Command[Int, AgentExecution, AgentExecutionListResponse[Seq[AgentExecution]]](repository, entity){
override def execute: Future[AgentExecutionListResponse[Seq[AgentExecution]]] = {
repository.getAllMastersForAgent(entity.agentId).map(ae => AgentExecutionListResponse(ae))
}
override def toString: String = "Command is: AgentExecutionListCommand"
}
case class AgentExecutionListResponse[Seq[AgentExecution]](response: Seq[AgentExecution]) extends CommandResponseWrapper
的方法getAllMastersForAgent在存儲庫中,返回一個未來[序號[AgentExecution],但是編譯器示出了在此行中的錯誤:
repository.getAllMastersForAgent(entity.agentId).map(ae => AgentExecutionListResponse(ae))
的錯誤是:表達類型AgentExecutionListResponse [Seq]不符合預期類型S_
這是什麼意思?
另一個錯誤是:
Error:(11, 189) org.jc.dpwmanager.commands.AgentExecutionListResponse[Seq[org.jc.dpwmanager.models.AgentExecution]] takes no type parameters, expected: one
case class AgentExecutionListCommand(repository: AgentExecutionRepository[Int, AgentExecution], entity: AgentExecution)(implicit ec: ExecutionContext) extends Command[Int, AgentExecution, AgentExecutionListResponse[Seq]](repository, entity){
爲什麼它說,它沒有類型參數,然後再次,希望之一。我不明白。請幫忙!
在此先感謝!
感謝您的答覆@Alexey羅曼諾夫。我在這裏寫的是AgentExecutionListCommand#execute必須返回一個CommandResponseWrapper的子類型,它也有一些嵌套類型(CommandResponseWrapper [可以是任何類型])。 –
@JorgeCespedes這似乎正是我在「修復可能只是」段落中所建議的。嘗試一下,看看它是否成功。 –
(儘管我沒有注意到另一個問題,迪瑪指出的那個問題) –