我还没有看到这样做的任何地方,但我有以下内容:
abstract class Player { val user_id: Long }
case class AlivePlayer(user_id: Long, target_id: Long) extends Player
case class DeadPlayer(user_id: Long) extends Player
def getPlayers(game: Game):Option[List[Player]] = DB.withConnection { implicit connect =>
SQL(
"""
SELECT * FROM game_participants WHERE game_id = {game_id})
"""
).on(
'game_id -> game.id
).as(Game.participantParser *)
}
在这种情况下,我收到编译器错误并显示以下消息
error: type mismatch; found : anorm.ResultSetParser[List[Product with Serializable with models.Player]] required: anorm.ResultSetParser[Option[List[models.Player]]]
).as(Game.participantParser *)
为什么仅将返回类型指定为 对我来说是不够的Option[List[Player]]
?