I have the following code:
private lazy val keys: List[String] = obj.getKeys().asScala.toList
obj.getKeys
returns a java.util.Iterator<java.lang.String>
Calling asScala
, via JavaConverers
(which is imported) according to the docs..
java.util.Iterator <==> scala.collection.Iterator
scala.collection.Iterator
defines
def toList: List[A]
So based on this I believed this should work, however here is the compilation error:
[scalac] <file>.scala:11: error: type mismatch;
[scalac] found : List[?0] where type ?0
[scalac] required: List[String]
[scalac] private lazy val keys : List[String] = obj.getKeys().asScala.toList
[scalac] one error found
I understand the type parameter or the java Iterator is a Java String, and that I am trying to create a list of Scala strings, but (perhaps naively) thought that there would be an implicit conversion.