编译错误:
发现[错误]:(((双精度,双精度))=> scala.concurrent.Future [(双精度,双精度)]
需要[错误]:(((AnyVal,AnyVal))=> scala.concurrent.Future [?] [错误](c:(Double,Double))=> Future(c).map(x => x )
IDE可以接受代码。
代码是使用for循环和yield编写的。我试图简化它。
def f(r: UUID, l: Int) = {
g(r).flatMap { (c: (Double, Double)) => /*** this part is just for the debugging ***/
Future(c).map(x=>x)
}
}
def g(r: UUID) = {
session.selectOne(
s"""
SELECT
${RR.x},
${RR.y}
FROM
${RR.g}
WHERE
${RR.r} = ?
ORDER BY
${RR.t} DESC
""",
r.toString
).map {
case Some(row) => (1.0,1.0) //will be replaced when it is working
case None => (0,0)
}
}
编译器发现 c 的类型为(AnyVal,AnyVal),我希望它为(Double,Double)
答案 0 :(得分:4)
实际上,这是在抱怨您传递给flatmap的方法的函数签名不是必需的。尝试在case None => (0,0)
函数中将case None => (0d, 0d)
行更改为g
。如果两个case分支返回不同的类型,则默认为两个的超级类型。在这种情况下,您的g
函数正在返回类型(AnyVal,AnyVal)