In Scala 2.8 this became much much easier, and there are two ways to achieve it. One that's sort of explicit (although it uses implicits):
import scala.collection.JavaConverters._
val myJavaIterable = someExpr()
val myScalaIterable = myJavaIterable.asScala
EDIT: Since I wrote this, the Scala community has arrived at a broad consensus that JavaConverters is good, and JavaConversions is bad, because of the potential for spooky-action-at-a-distance. So don't use JavaConversions at all!
And one that's more like an implicit implicit: :)
import scala.collection.JavaConversions._
val myJavaIterable = someExpr()
for (magicValue <- myJavaIterable) yield doStuffWith(magicValue)
Yes use implicit conversions:
Which can then be easily implemented:
In Scala 2.8 this became much much easier, and there are two ways to achieve it. One that's sort of explicit (although it uses implicits):
EDIT: Since I wrote this, the Scala community has arrived at a broad consensus that
JavaConverters
is good, andJavaConversions
is bad, because of the potential for spooky-action-at-a-distance. So don't useJavaConversions
at all!And one that's more like an implicit implicit: :)