Scala 2.8 includes a library that helps implicitly convert Scala objects to Java objects so you can keep your data in Scala-land while still using Java API calls. Just import this package in your code:jj
The problem is sometimes the conversion library fails at compile time because there are just too many possible conversions it can make. It can’t decide between all the possibilities. Talk about being a victim of your own success!
Here’s an example: I have a scala.Iterable of items, and I want to implicitly convert it to a java.lang.Iterable
But the implicit conversion dies here with the following message:
So here’s the fix: you can wrap your data to indicate the particular conversion you would like to occur. A list of wrappers is here. In my case, I want a java.lang.Iterable, so I’ll wrap it as so:
This removes the ambiguity, allowing the compiler to proceed without baffling itself by its own cleverness.