Back to Developer Roadmap

The apply method

src/data/roadmaps/scala/content/[email protected]

4.0826 B
Original Source

The apply method

The apply function is a so-called smart constructor. It's the most popular way in Scala to create new instances of data types. It's more flexible than a standard constructor because it allows for running certain logic before deciding whether an instance should be created, and, if yes, it can create an instance of a certain subtype while returning it as an instance of a supertype.

Visit the following resources to learn more: