scala: FOO cannot be cast to FOO

后端 未结 1 462
广开言路
广开言路 2021-02-10 22:22

In Scala, I am incredibly confused by this fairly tautological error message:

java.lang.ClassCastException: FOO cannot be cast to FOO

I would e

1条回答
  •  情书的邮戳
    2021-02-10 22:53

    I've run into similar issue, and I've converted my code to use IMain#mostRecentVar introduced in Scala 2.9. Here's from CompilerMatcher I wrote:

      val main = new IMain(s)
      main.compileSources(files.map(toSourceFile(_)): _*)
      code map { c => main.interpret(c) match {
        case IR.Error => error("Error interpreting %s" format (c))
        case _ => 
      }}
      val recent = main.mostRecentVar
      val holder = main.valueOfTerm(recent)
      if (holder != Some(expected))
        println("actual: " + holder.map(_.toString).getOrElse{"None"})
    

    0 讨论(0)
提交回复
热议问题