简体   繁体   English

`从非法包导入`错误

[英]`Import from illegal package` error

Anyone knows why I get the error Table.scala:8:0: Import from illegal package from the following code?任何人都知道为什么我会收到错误Table.scala:8:0: Import from illegal package from the following code?

Line 8 is referring to import scala.collection.JavaConversions._第 8 行是指import scala.collection.JavaConversions._

import org.allenai.common.Logging
import scala.collection.parallel.mutable

import java.io.FileReader
import au.com.bytecode.opencsv.CSVReader
import scala.collection.JavaConversions._

/** Created by i-danielk on 6/11/15.
  */
class Table(fileName: String) extends Logging {
  val (titleRow, contentMatrix) = readCSV(fileName)

  // reading from csv: for future
  def readCSV(file: String): (Array[String], Array[Array[String]]) = {
    val reader = new CSVReader(new FileReader(file))

    val fullContents = for {
      row <- reader.readAll
    } yield {
      row
    }
    (fullContents.head, fullContents.tail.toArray)
  }
}

For the sake of completeness: the Scala compiler will never (as far as I know) complain about an import from "an illegal package", so this must be a rule that someone has configured in a linter that the project is using (most likely Scalastyle ).为了完整起见:Scala 编译器永远不会(据我所知)抱怨从“非法包”导入,因此这必须是某人在项目正在使用的 linter 中配置的规则(很可能斯卡拉风格)。

Many people prefer the more explicit JavaConverters (with its asScala and asJava enrichment methods) to the magical implicit conversions of JavaConversions , so the solution is probably just to switch to that package.asJava神奇的隐式转换JavaConversions ,许多人更喜欢更显式的JavaConverters (及其asScalaasJava丰富方法),因此解决方案可能只是切换到该包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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