Scala: what is the purpose of 'override'

scala

Solution

In the case you are implementing an abstract method as in your example, it is not strictly necessary to add the `override` modifier.

However, in case you want to `override` a concrete method from the superclass, the `override` modifier is necessary. This is to avoid accidental overrides which could happen with mixing composition -- mixing-in traits during some refactoring could easily introduce a method definition that could be overridden by the method defined in the body of the class, hence the need for explicitly stating that a method is an override.

Problem

I'm not sure what the purpose of `override` keyword is, in scala. If I have ``` trait Shape { def foo(v: Int) } class Triangle extends Shape { override def foo(v: Int) {} } ``` it behaves (apparently at least) exactly the same as it does without `override`.

Original source