See: http://stackoverflow.com/questions/3075951/scala-importing-class
I have a file called CashFlow.scala
that I wish to use with another object Hello.scala
. Both are in the same directory:
class CashFlow(amt: Double, curr: String) {
def this(amt: Double) = this(amt, "GBP")
def doSomething {
println "do something"
}
}
object Hello extends App {
println "In Hello"
val c = new CashFlow(2000.0, "PHP")
c.doSomething
}
While these files can be run in the REPL, I like running them same as a Java file (automatically calls Hello
's main
method).
Here's how I did it. First, I compiled the classes:
$ scalac *.scala
Then I ran Hello
:
$ scala -cp . Hello
I've been working on interpreted languages for too long that I forgot about the compilation step. I wish there was a way to automatically compile a Scala class when changes are made to it.