Is Future[Future[Unit]] same as Future[Unit]. Why?

2019-08-22 03:02发布

问题:

This question already has an answer here:

  • Scala Try[Unit] confusion 2 answers
  • Scala: Why can I convert Int to Unit? 3 answers

Why in the following code, the compiler doesn't give error even if the return type is Future[Future[Unit]] instead of 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}
   }
标签: scala