gpt4 book ai didi

scala - 在 IntelliJ IDEA 中构建 scala 时出现 "not found: value classOf"错误,但在 maven 中正确构建

转载 作者:行者123 更新时间:2023-12-04 14:02:02 26 4
gpt4 key购买 nike

我写了一小段测试代码,正在用 IntelliJ IDEA 12 CE 编译它

import com.twitter.common.zookeeper.ZooKeeperClient
import org.mockito.Mockito

class MyResourceSpec {
val zkClient = mock(classOf[ZooKeeperClient])
...
}

我收到以下错误:
not found: value classOf
val zkClient = mock(classOf[ZooKeeperClient])
^

但是我能够使用 mvn compile 成功构建项目。此外,我在同一目录“MyOtherResourceSpec.scala”中有另一个测试文件,其中包含完全相同的代码行。

关于为什么这不能在 IDEA 中正确构建的任何想法?

我尝试过的事情:
  • 一位同事建议IDEA可能无法将其识别为scala文件,我尝试单击顶级项目然后
    单击 Maven > 重新导入。
  • 重启 IntelliJ
  • 复制所有从“MyOtherResourceSpec.scala”导入的内容,以防丢失
  • 使用 Mockito.mock(classOf[ZooKeeperClient])
  • 最佳答案

    好的,我通过点击 解决了这个问题文件 > 使缓存无效 并重新启动 IntelliJ。然后我不需要导入 Predef.classOf。

    我还必须删除以下导入语句:

    import scala.Predef.String

    关于scala - 在 IntelliJ IDEA 中构建 scala 时出现 "not found: value classOf"错误,但在 maven 中正确构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17603684/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com