Starting with Scala version 2.9 there exists a handy converter to convert from java.util.List
and other collections to Scala's data structures by writing something like this:
import scala.collection.JavaConverters._
def scalaVersion = callJavaMethod.asScala
This is a lovely little feature, as it allows one to exploit the advantages of Scala when interacting with existing Java code.
However, I am uncertain about the involved time and space complexity and could not find anything in the official documentation, hence, the following question:
Where can I get information on the complexity (time and space) of the JavaConverters?
Various
JavaConverters
classes are using Adapter pattern to wrap original Java collection (underlying
) and provide Scala interface. Thus both converting and accessing converted collections is constant in time (O(1)
) introducing only minor overhead.For instance this is the full source code of
JListWrapper
:Also note that converting Java collection to Scala and then back to Java yields the original collection, not double-wrapper.