简体   繁体   中英

scala packages import error in IntelliJ IDEA

I am trying to compile scala code in IntelliJ IDEA (community 2019.2) on MacBook. My scala version: 2.13.0.

In the code:

import scala.collection.JavaConverters._

is greyed out and "JavaConverters._" is crossed-out.

and

 import scala.collection.JavaConversions._

the "JavaConversions._" is marked as RED, which means that it cannot be resolved.

I also tried

   import scala.jdk.CollectionConverters

which is also greyed out (which means it is not used)

But, I can do the same things in command line.

Are there something I missed in IntelliJ IDEA ?

In repl behavior is the same

[IJ]sbt:scala213demo1> console
[info] Starting scala interpreter...
Welcome to Scala 2.13.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.

scala> import scala.collection.JavaConversions._
                               ^
       error: object JavaConversions is not a member of package collection

scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._

scala> import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters._

If behavior in repl is different for you then you start repl with different version of scala.

In 2.13 correct is

import scala.jdk.CollectionConverters._

scala.collection.JavaConverters._ is deprecated, scala.collection.JavaConversions was deprecated even in 2.12 and now unavailable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM