scala: FOO cannot be cast to FOO

后端 未结 1 464
广开言路
广开言路 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)
提交回复
热议问题