Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to use OVERRIDE modifier
What is the purpose of the
override modifier and how to use it?
When member of the child class overrides a concrete member of the parent class, Scala requires the
override modifier to be used. The modifier is optional if the member implements an abstract member with the same name. However, it is forbidden if the member does not override or implement some other member in the base class.
This rule provides information for the compiler that can help avoid errors and makes code evolution safer. For example, instead of the accidental override (a common manifestation of the problem known as the fragile base class), the compiler will give the error:
error overriding method
override modifier is used correctly.
Odersky, M: Programming in Scala, 3rd, 2016