首页 > 解决方案 > 实例化规范类时出现“找到接口 scalaz.Tree,但应使用类”错误

问题描述

我使用以下方法成功编译了以下 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 = new IntroSpec似乎不起作用。我想实例化并运行IntroSpec类。我怎样才能正确地做到这一点?谢谢你。

介绍.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
}

标签: scalascalaz

解决方案


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


推荐阅读