根据Scala Spec中对象的定义,导入的对象被永久隐藏

根据Scala Spec中对象的定义,导入的对象被永久隐藏,scala,Scala,我正在尝试编写规范,但出现编译错误: imported `Writer' is permanently hidden by definition of object ZipWriter in package util [error] import com.thing.util.Writer 我有一个目标: object Writer 我的规范是这样的: package com.thing.util import com.thing.util._ import java.io.File

我正在尝试编写规范,但出现编译错误:

 imported `Writer' is permanently hidden by definition of object ZipWriter in package util
 [error] import com.thing.util.Writer
我有一个目标:

object Writer
我的规范是这样的:

package com.thing.util

import com.thing.util._
import java.io.File

class WriterSpec {
  behavior of "buildFilePath"

  it must "append the compressionExtension to the file" in {
    val files: Array[File] = Array(new File("/some/filepath.someData"))

    val compressed = Writer.buildFilePath(files, "gz")
    compressed must be("/some/filepath.someData.gz")
  }    
}
这是可行的,但如果我试图直接在import语句中指定Writer,则所有操作都会失败。有什么好处

package com.thing.util

import com.gemini.util.Writer
import java.io.File

class WriterSpec {
  behavior of "buildFilePath"

  it must "append the compressionExtension to the file" in {
    val files: Array[File] = Array(new File("/some/filepath.someData"))

    val compressed = Writer.buildFilePath(files, "gz")
    compressed must be("/some/filepath.someData.gz")
  }    
}
在文件开头从您自己的包中导入任何内容(或所有内容)是没有意义的,因为所有内容都已可见

我试图直接在import语句中指定Writer,但都失败了


消息说,因为已经有
com.thing.util.Writer
,导入
com.gemini.util.Writer
不会做任何事情,
Writer
在您的代码中仍然意味着
com.thing.util.Writer
(如果您需要使用
com.gemini.util.Writer
,您需要将其写出或使用重命名导入)。通常它应该是一个警告,您必须传递将警告转化为错误的编译器选项。

您引用的错误引用了ZipWriter,但没有代码提到该对象。您的答案引用了com.gemini.util.Writer,它与OP和答案中其他地方的包不同。它应该是com.thing.util.Writer吗?您在OP中错过了导入com.gemini.util.Writer。
package com.thing.util

import com.thing.util._