scala - 实例化规范类时出现“找到接口 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
}
解决方案
您有 scala 版本冲突:specs2 使用 scala 2.11,而 scalaz 使用 scala 2.10。
推荐阅读
- c# - 使用 PhotoCapture Unity C# 拍摄多张照片
- r - 是否可以将 ... 的内容分配给另一个变量?
- string - 如何在 RPGLE 中将字符串与换行符连接起来?
- php - 数组中的多个文本框
- java - Spring Rest:具有多个参数的过滤器 api
- database-design - 存储大量数据以快速请求的最佳方式
- image - Flutter 图像压缩
- spring-boot - 未从 Spring Cloud 自定义过滤器调用 @ControllerAdvice 处理程序
- php - 如何使用 Laravel 的 Storage Facade 存储多个上传的文件
- javascript - 检查数组是否包含不同的值