5

I have a simple class calc that squares and cubes the input:

object calc2 {

  def square(nmr: Int) = {
    calc.square(nmr)
  }

  def cube(nmr: Int) = {
    calc.cube(nmr)
  }

  def square(nmr: Double) = {
    calc.square(nmr)
  }

  def cube(nmr: Double) = {
    calc.cube(nmr)
  }
}

And I'm using a Scala Worksheet in Eclipse with calls to this object:

object test {
  calc2.square(3)                                 //> res0: <error> = 9.0
  calc2.cube(3)                                   //> res1: <error> = 27.0
  calc2.square(3.0)                               //> res2: <error> = 9.0
  calc2.cube(3.0)                                 //> res3: <error> = 27.0
}

However I get a error in the Editor for every line which says

value square is not a member of object exercises2.calc2

enter image description here

As you can see the worksheet seems to do the calculation. So why am I getting this error?

Pedro Gordo
  • 1,825
  • 3
  • 21
  • 45

1 Answers1

0

The below solution works for the same problem in IntelliJ IDEA, but I reckon something similar can be set in Eclipse as well.

The reason why the worksheet doesn't recognise your totally existing members is because they have been written (or re-written) after the last compilation. You can force the worksheet to make the project before run, thus making all the newly written or modified parts of your code visible to the underlying REPL. Credit goes to this comment poster. In IntelliJ IDEA you set it as below, clicking on the wrench icon on your worksheet header:

enter image description here

bugfoot
  • 667
  • 7
  • 20