Scala Pattern Matching

Pattern Matching Pattern matching allows us to make a programmatic choice between multiple conditions. Pattern matching is an essential and powerful feature of the Scala language. With Scala’s pattern matching, we can include types, wildcards, sequences, regular expressions in case statements.   Example of pattern matching   Here is a simple example of pattern matching […]

Case class in Scala

Case class   A case class provides the same facilities as a normal class, but the compiler generates toString, hashCode, and equals methods (which you can override). Case classes can be instantiated without the use of the new statement. By default, all the parameters in the case class’s constructor become properties on the case class. […]

Scala Traits

Trait A trait is a kind of class that enables multiple inheritance. Classes, case classes, objects, and (yes) traits can all extend no more than one class but can extend multiple traits at the same time. Unlike the other types, however, traits cannot be instantiated. Traits can have implemented methods. They are similar to Java […]

Scala Inheritance

Inheritance   Like Java, Scala supports single inheritance, not multiple inheritance. A child (or derived) class can have one and only one parent (or base) class. The sole exception is the root of the Scala class hierarchy, Any, which has no parent.   “extends” keyword should be used when a child class inherits a parent […]

Scala Objects

In Scala, an object can mean an instance of a class. Also, “object” can be used as a keyword. Lets see usage of object as keyword in this article.   Singleton Object   A singleton is a class that can have only one instance. We can use the object keyword to create a Singleton object […]