2021年3月11日星期四

Why Future(1) return diffrent result between repl and compiled prog?

Use future in repl:

scala> val a=Future{1}  a: scala.concurrent.Future[Int] = Future(<not completed>)    scala> a.value  res0: Option[scala.util.Try[Int]] = Some(Success(1))  

return Some(Success(1))

Use it in IDEA:

object A extends App{   val a=Future{1}   println(a.value)  }  

return None:

"C:\Program Files\Java\jdk1.8.0_201\bin\java.exe"...  None  

Why?There is no something like Thread.Sleep,so in any situation,I think the Future will return immediately,give me Some(Successs(1))

Thanks!

https://stackoverflow.com/questions/66592765/why-future1-return-diffrent-result-between-repl-and-compiled-prog March 12, 2021 at 09:06AM

没有评论:

发表评论