如果小于Int.max时他不会报错
def sumcount(str:String): Int ={ val ints = for(c <- str)yield { println(c.asInstanceOf[Int]) ; c.asInstanceOf[Int]} println(ints.reduce(_*_)) println(Int.MaxValue) ints.sum } sumcount("Hello")
72
101
108
108
111
825152896
2147483647
def sumcount(str:String): Long ={ val ints = for(c <- str)yield { println(c.asInstanceOf[Long]) ; c.asInstanceOf[Long]} println(ints.reduce(_*_)) println(Int.MaxValue) println(Long.MaxValue) ints.sum } sumcount("Hello")
时间: 2024-10-29 09:34:35