实例化规范类时出现“找到接口scalaz.Tree,但预期是类”错误

时间:2018-11-06 14:31:56

标签: scala scalaz

我使用以下命令成功编译了以下2个scala文件:

scalac -classpath "../specs2_2.11-2.4.jar;../scalaz-core_2.10.0-M6-7.0.0-M2.jar;classes" -d classes *.scala

当我跑步时:

scala -classpath "../specs2_2.11-2.4.jar;../scalaz-core_2.10.0-M6-7.0.0-M2.jar;classes" Chapter1.Introduction

我明白了

Is 'Herculaneum' a palindrome? false
java.lang.IncompatibleClassChangeError: Found interface scalaz.Tree, but class was expected
...

val p =新的IntroSpec 似乎不起作用。我想实例化并运行 IntroSpec 类。如何正确执行?谢谢。

Introduction.scala

package JustTrying
import Chapter1.Introduction
import org.specs2.mutable._

class IntroSpec extends Specification {
  "The phrase 'Never odd or even'" should {
    "be a palindrome" in {
      Introduction.isPalindrome("Never odd or even") must beTrue
    }
  }
}

IntroSpec.scala

package Chapter1
import JustTrying.IntroSpec

object Introduction extends App {
  def isPalindrome(word: String) = {
    val modifiedWord = word.toLowerCase.replaceAll("[^a-z0-9]", "")
    val reversed = modifiedWord.reverse
    modifiedWord == reversed
  }
  println("Is 'Herculaneum' a palindrome? " + isPalindrome("Herculaneum"))
  val p = new IntroSpec
}

1 个答案:

答案 0 :(得分:0)

您遇到了scala版本冲突:specs2使用scala 2.11,而scalaz使用scala 2.10。