How to get Scala List from Java List?

前端 未结 6 1285
半阙折子戏
半阙折子戏 2021-01-29 23:23

I have a Java API that returns a List like:

public List getByXPath(String xpathExpr)

I am using the below scala code:

         


        
6条回答
  •  庸人自扰
    2021-01-29 23:40

    EDIT: Note that this is deprecated since 2.12.0. Use JavaConverters instead. (comment by @Yaroslav)

    Since Scala 2.8 this conversion is now built into the language using:

    import scala.collection.JavaConversions._
    
    ...
    
    lst.toList.foreach{ node =>   .... }
    

    works. asScala did not work

    In 2.12.x use import scala.collection.JavaConverters._

    In 2.13.x use import scala.jdk.CollectionConverters._

提交回复
热议问题