Future [Future [Unit]]是否与Future [Unit]相同?为什么?

时间:2019-07-19 16:43:24

标签: scala

为什么在以下代码中,即使返回类型为Future[Future[Unit]]而不是Future[Unit],编译器也不会给出错误?

//compiles even though return is Future[Future[Unit]]. Not expected.
   def test1:Future[Unit] = Future{
    Future{   println("something")}
   }
   //doesn't compile because return is Future[Future[Int]] . Expected
   def test:Future[Int] = Future{
       Future{1}
   }

0 个答案:

没有答案