Scala 2.13之後,並行集合模塊變成了外部庫,直接像2.12那樣寫如下的代碼,IDE會報“Cannot resolve symbol par”:
cities => (cities.par map getWeatherData).toList
這個時候,需要在maven項目的pom.xml中手動導入如下依賴:
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parallel-collections_2.13</artifactId>
<version>0.2.0</version>
</dependency>
爲了使用並行運行的par()方法,在導入maven依賴後,只需要在代碼文件中導入如下的包就行了:
import scala.collection.parallel.CollectionConverters._
關於par在2.13版本後無法解析的參考鏈接:
https://stackoverflow.com/questions/57287607/missing-par-method-from-scala-collections
同時XML和Swing、parser-combinators等模塊也不默認包括在Scala包中了,如果是要解析XML,也需要在maven項目的pom.xml中加入如下依賴:
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-xml_2.13</artifactId>
<version>1.2.0</version>
</dependency>
關於解析XML加依賴的參考鏈接:
https://blog.csdn.net/xiaoduan_/article/details/80998840
以下鏈接能搜索可導入的maven依賴與對應版本等信息: