Java – Why does java use an @Override annotation, instead of a modifier

java

What were the motivations for java to use the @Override annotation, instead of creating a new override modifier?

@Override
public String toString() {
   return "";
}

vs.

public override String toString() {
   return "";
}

Best Answer

@Override was originally not in the language. When the need was felt to add it, it was easier to use a generic mechanism (annotations) than to add a new keyword to the language. Adding a new keyword is always an incompatible change since it can break programs which use that words as an identifier.

In languages which add an override marker right from day one, it is quite often a keyword (examples are Kotlin and Scala), in Java it was a matter of staying backwards-compatible with older Java version which did not have any override marker.