I get a weird compilation error in the small Scala exercise I am working on.
I have this method that is supposed to keep on asking user input until a correct answer is provided. Alas I am stumbled at the first case in my pattern matching:
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)
}
}
}
The IDE underlines guess(a)
with the error "Int doesn't take parameters". Running sbt compile
from the console confirms this error:
> 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
There are few different Stackoverflow tickets for the same error message, but they're for different scenarios. In mine here it looks like a method who takes an Int
parameter is being rejected. If you could please give me a hint this would help me a lot.
Rename the guess
parameter (or the method name, so it's something different) - the parameter is the first guess
in scope, so the compiler thinks you're trying to call it as a function.