我试图了解 Scala for-loop 隐式框/拆箱“数字”类型的行为。为什么这两个第一个失败而其余的都不失败?
1) 失败:
scala> for (i:Long <- 0 to 10000000L) {}
<console>:19: error: type mismatch;<br>
found : Long(10000000L)
required: Int
for (i:Long <- 0 to 10000000L) {}
^
2> 失败:
scala> for (i <- 0 to 10000000L) {}
<console>:19: error: type mismatch;
found : Long(10000000L)
required: Int
for (i <- 0 to 10000000L) {}
^
3)作品:
scala> for (i:Long <- 0L to 10000000L) {}
4)作品:
scala> for (i <- 0L to 10000000L) {}