Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

EDIT: Quoting, as OP updated his comment as I responded.

>But Scala doesn't let that happen nicely does it? Interfacing with Java collections feels just awkward.

Awkward? The Scala interface is better than the native Java interface itself. I can perform a map, reduce, filter on the Java array in Scala, something that is impossible in Java. How can it be more awkward than Java itself?



What I'm saying is, if you decided to say, use a Java HashMap in one part of your code for performance reasons. You'll have to live with that with the rest of your code. Half of the classes in the scala library doesn't like it because it doesn't implement the required traits and as far as I can tell there is no nice way of converting between collections.


import scala.collection.JavaConverters._

Scala doesn't provide a built in for your specific case but

import scala.collection.breakOut

and you can convert mutable Java hash map to immutable scala map

b = a.asScala.map(p => p)(breakOut)

where b : scala.collection.immutable.HashMap[java.lang.String,Int]

and a : java.util.HashMap[String,Int]

Not too bad at all. Moreover, why would you want to convert a Java map to Scala if you specifically used the Java map to improve performance? How is this any worse than coding in Java itself?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: