Is there an easy way to get the Scala REPL to reload a class or package?

Posted by Rex Kerr on Stack Overflow See other posts from Stack Overflow or by Rex Kerr
Published on 2010-03-18T17:19:09Z Indexed on 2010/03/18 17:21 UTC
Read the original article Hit count: 439

Filed under:
|
|

I almost always have a Scala REPL session or two open, which makes it very easy to give Java or Scala classes a quick test. But if I change a class and recompile it, the REPL continues with the old one loaded. Is there a way to get it to reload the class, rather than having to restart the REPL?

Just to give a concrete example, suppose we have the file Test.scala:

object Test { def hello = "Hello World" }

We compile it and start the REPL:

~/pkg/scala-2.8.0.Beta1-prerelease$ bin/scala
Welcome to Scala version 2.8.0.Beta1-prerelease
(Java HotSpot(TM) Server VM, Java 1.6.0_16).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Test.hello
res0: java.lang.String = Hello World

Then we change the source file to

object Test {
  def hello = "Hello World"
  def goodbye = "Goodbye, Cruel World"
}

but we can't use it:

scala> Test.goodbye
<console>:5: error: value goodbye is not a member of object Test
       Test.goodbye
            ^

scala> import Test;
<console>:1: error: '.' expected but ';' found.
       import Test;

© Stack Overflow or respective owner

Related posts about scala

Related posts about repl