【发布时间】:2017-05-18 11:33:16
【问题描述】:
我发现为了模式匹配Future毛皮Success/Failure,我需要使用andThen(或onComplete,onSuccess...)并且不能使用map .这是为什么呢?
我想做的事情(简单来说,我也在匹配Success等等):
val f1 = Future(throw new Exception("Oops"))
f1 map { case Failure(e) => ??? }
给予:
error: constructor cannot be instantiated to expected type;
found : scala.util.Failure[T]
required: Nothing
f1 map { case Failure(e) => ??? }
我最终做了什么:
val f1 = Future(throw new Exception("Oops"))
f1 andThen { case Failure(e) => ??? }
我想了解为什么这里不能使用map。
【问题讨论】:
标签: scala pattern-matching future