Convert from scala.collection.Seq to java.util.List in Java code

You’re on the right track using JavaConversions, but the method you need for this particular conversion is seqAsJavaList: java.util.List<String> convert(scala.collection.Seq<String> seq) { return scala.collection.JavaConversions.seqAsJavaList(seq); } Update: JavaConversions is deprecated, but the same function can be found in JavaConverters. java.util.List<String> convert(scala.collection.Seq<String> seq) { return scala.collection.JavaConverters.seqAsJavaList(seq); }

Java Scala interop: transparent List and Map conversion

Trust me; you don’t want transparent conversion back and forth. This is precisely what the scala.collection.jcl.Conversions functions attempted to do. In practice, it causes a lot of headaches. The root of the problem with this approach is Scala will automatically inject implicit conversions as necessary to make a method call work. This can have some … Read more

How to learn about using scala.None from Java using javap?

There are rules how Scala code is compiled to JVM-bytecode. Because of potential name clashes the generated code is not always intuitive to understand but if the rules are known it is possible to get access to the compiled Scala code within Java. Attention: While writing this, I noticed that javac and eclipse-javac behave differently … Read more

How to use scala.None from Java code [duplicate]

The scala.None$.MODULE$ thing doesn’t always typecheck, for example this doesn’t compile: scala.Option<String> x = scala.None$.MODULE$; because javac doesn’t know about Scala’s declaration-site variance, so you get: J.java:3: incompatible types found : scala.None$ required: scala.Option<java.lang.String> scala.Option<String> x = scala.None$.MODULE$ ; This does compile, though: scala.Option<String> x = scala.Option.apply(null); so that’s a different way to get a … Read more

How can I convert Scala Map to Java Map with scala.Float to java.Float k/v conversion

The solution linked to by @pagoda_5b works: Scala convert List[Int] to a java.util.List[java.lang.Integer] scala> import collection.JavaConversions._ import collection.JavaConversions._ scala> val m = mapAsJavaMap(Map(1 -> 2.1f)).asInstanceOf[java.util.Map[java.lang.Integer, java.lang.Float]] m: java.util.Map[Integer,Float] = {1=2.1} scala> m.get(1).getClass res2: Class[_ <: Float] = class java.lang.Float