Gary Sieling

Box/unbox a primitive in Scala

If you have a primitive type in Scala, you may need to “box” it, by turning it into a real JVM object, like so:

String.format("%-30s: %.2f ± %0.2f", kv._1, Double.box(kv._2), Double.box(kv._3))

This creates “java.lang.Double” from “scala.Double”.

Exit mobile version