当我运行以下代码时,我收到一些错误:
Error:(15, 25) missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: ?
testFuture onComplete({
^
代码:
object TestFuture extends App{
val exe = ExecutionContext.fromExecutor(Executors.newCachedThreadPool())
testFuture onComplete({
case Success((str,i)) =>{
println(str,i)
}
case Failure(e) =>{
e.printStackTrace()
}})(exe)
println(Runtime.getRuntime.availableProcessors())
Thread.sleep(2000)
def testFuture:Future[(String,Int)] = Future[(String,Int)] {
Thread.sleep(1000)
("oh my sky",12)
}(exe)
}
当我装饰' val exe'与隐含的'并且在没有明确使用' exe'之前调用currying函数。像下面的代码,它是正确的。你能告诉我为什么吗?
object TestFuture extends App{
implicit val exe = ExecutionContext.fromExecutor(Executors.newCachedThreadPool())
testFuture onComplete({
case Success((str,i)) =>{
println(str,i)
}
case Failure(e) =>{
e.printStackTrace()
}})
println(Runtime.getRuntime.availableProcessors())
Thread.sleep(2000)
def testFuture:Future[(String,Int)] = Future[(String,Int)] {
Thread.sleep(1000)
("oh my sky",12)
}
}
答案 0 :(得分:1)
我猜,中缀方法调用不支持多个参数列表。尝试使用点符号:
testFuture.onComplete{
case Success((str,i)) =>
println(s"$str, $i")
case Failure(e) =>
e.printStackTrace()
}(exe)