The Scala package objectTopWhere to put package objectsContents

Where to put package objects

Package objects are compiled to class files named package.class which are the located in the directory of the package that they augment. So the package object fruits would be complied to a class with fully qualified name gardening.fruit.package (Note that, even though package is a reserved word in Java and Scala, it is still allowed as part of a class name on the JVM level. In Scala, you can even define it directly, using backticks:

package gardening.fruits
object `package` { ... }

It's useful to keep the same convention for source files. So you would typically put the source file of the package object gardening.fruits into a file named package.scala that resides in the gardening/fruits directory.

Next: The Scala package object


The Scala package objectTopWhere to put package objectsContents