When I try to run code based on this example, I get the following warning:
warning: object JavaConversions in package collection is deprecated (since 2.12.0): use JavaConverters
AFAICT, the lines responsible for the warning are these:
import scala.collection.JavaConversions._
/* ... */
for ((k,v) <- environmentVars) println(s"key: $k, value: $v")
Replacing the import
line with
import scala.collection.JavaConverters._
...is not enough; doing this alone results in the error:
error: value withFilter is not a member of java.util.Map[String,String]
for ((k,v) <- environmentVars) println(s"key: $k, value: $v")
What else must be done?
You need to add the asScala
method:
import scala.collection.JavaConverters._
for ((k,v) <- environmentVars.asScala) println(s"key: $k, value: $v")
Since Scala 2.13, this is now CollectionConverters
:
import scala.jdk.CollectionConverters._
for ((k,v) <- environmentVars.asScala) println(s"key: $k, value: $v")
FYI, scala.collection.JavaConverters has now been replaced with scala.jdk.CollectionConverters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With