I’m trying to get started with Scala and cannot get out of the starting gate.
A file consisting of the line
package x
gives me
error: illegal start of definition
Regardless of what x is and regardless of where I put the file (I had a theory that I had to place the file in a directory hierarchy to match the package definition, but no). I get the same error with the example code from the web site and with the REPL.
It looks like you’re trying to declare the
packagemembership in a Scala script (run using thescalacommand) or in the REPL.Only files defining just classes and objects which are compiled with
scalacmay be defined as belonging to a package.When you run code in a script or a REPL session, behind the scenes it is actually compiled inside a method of an object, in which scope a package declaration wouldn’t be legal.