Singleton Objects: Standalone

In this lesson, you will learn how to write a singleton standalone object.

We'll cover the following

Standalone Objects

Standalone objects are singleton objects which are not attached to any class, i.e., they don’t have the same name as any class. Hence, they can literally stand alone.

Up until now, we haven’t been able to execute our ChecksumAccumulator program. This is where standalone objects come in. They can be used for defining the entry point of a Scala application, an executable program. To use a standalone object for this purpose, you need to create a main method that takes a single parameter of type Array[String] (an array of strings). Now all you have to do when you want to execute your program is run the standalone object.

Let’s define a standalone object for our ChecksumAccumulator program so it can be used as an application.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy