我想寫一個函數,它將在未來處理異常並返回新的未來,但我遇到了麻煩,不能使作爲簽名要求的錯誤消息斯卡拉類型不匹配:default.type(與底層類型A1 => B1)
scala> def composeHandlingFuture[T](fut: Future[T], default: T): Future[T] =
| fut recover { case e: Exception => default }
<console>:19: error: type mismatch;
found : default.type (with underlying type A1 => B1)
required: T
fut recover { case e: Exception => default }
^
意識不default.type
等於T
?它與type A1 => B1
有什麼關係?
任何幫助表示讚賞。
P.S.我使用Scala的2.10.1
我不能解釋錯誤消息,但刪除顯式返回類型可以讓你定義函數沒有它抱怨 – theon
是的,但返回類型變成scala.concurrent.Future [Any],這不是我想要的 – Zotov
啊,是的,剛纔也注意到了。 IntelliJ說謊並且說返回類型是'Future [T]' – theon