Scala:int在递归调用中不接受参数



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

我有这种方法应该继续询问用户输入,直到提供正确的答案为止。las,我在模式匹配的第一个情况下偶然发现了:

  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)
      }
    }
  }

IDE强调了guess(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

对于同一错误消息,很少有不同的堆叠式门票,但它们适用于不同的方案。在我的这里,看起来像是采用Int参数的方法正在被拒绝。如果您可以给我一个提示,这将对我有很大帮助。

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

最新更新