title: error: illegal start of statement (no modifiers allowed here) private def hasNoDuplicates(line: Array[Int]) = .... in Scala
body: <p>I am trying to validate a Soduko board. my input is of type Any, so first, I want to change that to Int. and validate that, I write the following code but it can not return the true result and return some error. how can I handle the problem of code? validate method comprised of two other method, one for convert Any to Int and another for validate Sudoko board.</p>
  <pre><code>def validate(lines: Array[Option[Any]]*): Boolean = {
  
  
  object BoardParser {
  
    /**
      * Parse a Sudoku board from varargs
      * Board needs to have 9 rows, 9 columns &amp; all Int or Long values for non-empty cells, to be accepted
      *
      * @param board Variable number of optional arrays
      * @return A 2D Int array representing the basic Sudoku board
      */
    def getValidBoard(board: Array[Option[Any]]*): Array[Array[Int]] = {
      def validateBoard() = {
        if (board.length != 9 || board.transpose.length != 9) {
          throw new IllegalArgumentException(&quot;Board must be a 2D array of size 9x9&quot;)
        } else if (!board.forall(isAllNumbers)) {
          throw new IllegalArgumentException(&quot;Board must contain only Int or Long values&quot;)
        }
      }
  
      validateBoard()
      board.map(toNumbers).toArray
    }
  
    private def isAllNumbers(line: Array[Option[Any]]) = {
      line.forall {
        case Some(_: Int) =&gt; true
        case Some(_ : Long) =&gt; true
        case None =&gt; true
        case _ =&gt; false
      }
    }
  
    private def toNumbers(line: Array[Option[Any]]) = {
      line.map {
        case Some(x: Int) =&gt; x
        case Some(x: Long) =&gt; x.toInt
        case None =&gt; 0
        case _ =&gt; throw new IllegalArgumentException
      }
    }
  
  }
  val valid_board = getValidBoard(lines)
  
  def new_validate(board: Array[Array[Int]]): Boolean = {
    lazy val rowsValid = board.forall(hasNoDuplicates)
    lazy val columnsValid = board.transpose.forall(hasNoDuplicates)
    lazy val cellsValid = squaresHaveNoDuplicates(board)
  
    rowsValid &amp;&amp; columnsValid &amp;&amp; cellsValid
  }
  
  private def hasNoDuplicates(line: Array[Int]) = line.distinct.count(1 to 9             contains _) == line.count(_ != 0)
  
  private def squaresHaveNoDuplicates(matrix: Array[Array[Int]]) = {
    val rowBlocks = matrix.grouped(3).toArray
    val transposed = rowBlocks.map(_.transpose)
    val squares = transposed.map(_.grouped(3).toArray)
    val squaresFlattened = squares.map(_.map(_.flatten))
  
    squaresFlattened.forall(_.forall(hasNoDuplicates))
  }
  return new_validate(valid_board)
  </code></pre>