0

在我正在进行的小型 Scala 练习中,我遇到了一个奇怪的编译错误。

我有这种方法应该一直询问用户输入,直到提供正确的答案。唉,我在模式匹配的第一个案例中被绊倒了:

  override def guess(guess: Int):Unit = {
    val guessIndex = binary(array, guess)
    guessIndex match {
      case -1 => {
         val nextAttempt = StdIn.readLine(s"Please be attentive $guess is outside the search range" 
              +" (0 to $upperBound). Try again: \n");
         val a = validateType[Int](nextAttempt)
         guess(a)
      }
    }
  }

IDEguess(a)用错误“Int 不接受参数”下划线。sbt compile从控制台运行确认此错误:

> compile
[info] Compiling 2 Scala sources to /home/vgorcinschi/Documents/eclipseProjects/Algorithms/Chapter 1 Fundamentals/algorithms1_4_34/target/scala-2.12/classes...
[error] /home/vgorcinschi/Documents/eclipseProjects/Algorithms/Chapter 1 Fundamentals/algorithms1_4_34/src/main/scala/ca/vgorcinschi/algorithms1_4_34/hotandcold/HotAndColdImpl.scala:23: Int does not take parameters
[error]          guess(a)
[error]               ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 0 s, completed 6-May-2017 6:47:58 PM

对于相同的错误消息,几乎没有不同的 Stackoverflow 票证,但它们适用于不同的场景。在我这里看起来像一个接受Int参数的方法被拒绝了。如果你可以请给我一个提示,这将对我有很大帮助。

4

1 回答 1

3

重命名guess参数(或方法名称,因此有所不同) - 参数是guess范围内的第一个参数,因此编译器认为您正在尝试将其作为函数调用。

于 2017-05-07T01:11:15.143 回答