Reputation:
I am trying to figure out how to split up a scala program into multiple files.
My background is mostly C programming. I want to learn how to do the equivalent of C's #include
in Scala.
I am trying as follows:
package test
object HelloObject {
def main(args: Array[String]) {
HelloTwoObject.foo()
}
}
and in another file I have
package test
object HelloTwoObject {
def foo(){
println("Hello Foo!")
}
}
Then I do scalac hello.scala hellotwo.scala
Then I go into the folder test and try scala HelloObject.class
, but it doesn't work. It gives me a long error
What is wrong here?
Upvotes: 2
Views: 8921
Reputation: 3526
The specific issue in your case is the wrong compilation command, like @KimStebel said above.
But to answer your specific question:as long as both the files/functions/objects are within the same package,(which you are already doing, as package test
) it will automatically link.
Upvotes: 0
Reputation: 42047
The scala executable takes a script file or an object name as an argument, but HelloObject.class
is neither.
It should just be scala test.HelloObject
.
Upvotes: 4