2

I am trying to run this program but it is telling me that r is not found. How do you call the method since it is in a class? (I am assuming that the error is because of this)

package pack

class Sud(val grid: List[List[Int]]) {

  def r(r: Int): List[Int] =
  //code
}

object Sud
{
  def main(args: Array[String]) 
  {

     val puzzle=new Sudoku(List(
          List(0, 0, 9, 0, 0, 7, 5, 0, 0),
        //rest of Sudoku puzzle created by repeating the above statement

          println(r(0)) //ERROR given here
  }
}
1
  • 2
    Well, it's a class method, so you need an instance of a class to call it. If you want free-functions, you will have to put them in an object and import said object. Commented Nov 25, 2013 at 12:08

1 Answer 1

11

As said in the comments, in your code r is a class method. Hence you need to Instantiate your Class Sud in order to call that method.

val inst: Sud = new Sud(puzzle)

println(inst.r(0))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.