tags:

views:

418

answers:

3

I use a lot of scala maps, occasionally I want to pass them in as a map to a legacy java api which wants a java.util.Map (and I don't care if it throws away any changes).

+2  A: 

Scala provides wrappers for Java collections so that they can be used as Scala collections but not the other way around. That being said it probably wouldn't be hard to write your own wrapper and I'm sure it would be useful for the community. This question comes up on a regular basis.

Erik Engbrecht
I might just do that.
Michael Neale
+5  A: 

An excellent library I have found that does a better job of this:

http://github.com/jorgeortiz85/scala-javautils

(bad name, awesome library). You explicitly invoke .asJava or .asScala depending on what direction you want to go. No surprises.

Michael Neale
+1  A: 

This question and answer discuss this exact problem and the possible solutions. It advises against transparent conversions as they can have very strange side-effects. It advocates using scala-javautils instead. I've been using them in a large project for a few months now and have found them to be very reliable and easy to use.

Dave
I agree - the transparent conversions often cause more hassle then they save (its not a total wash, sometimes they are handy). Having Seq methods on java arrays, and eventually other collection types is kinda nice, but beyond that, I like scala-javautils. Wish I found out about it ages ago.
Michael Neale