I was trying to create an array containing all Int
, Long
and Double
types. However, I found that the Long
and Int
types are automatically converted to Double
.
Here's a minimal example,
object HelloWorld {
def main(args: Array[String]): Unit = {
val types = Array[Byte]('i', 'l', 'd', 'd')
val array = Array[String]("1", "2000000", "20.0", "2020.0")
val values = array.zip(types) map { case (s, t) =>
t match {
case 'i' => s.toInt
case 'l' => s.toLong
case 'd' => s.toDouble
}
}
values.foreach { println }
}
}
The result is
1.0
2000000.0
20.0
2020.0
How can I avoid such conversion? Thanks.