For some time now Java compilers allow you indicate some methods in your class definition as overridden methods.

You do this by annotating the method signature with a code snippet such as


@Override
public void somemethod(){}

By doing so you tell the compiler to see if this annotated method exists in base classes or in the inheritance hierarchy. If it is, nothing happens. If it isn't you, the programmer, have made a mistake, because you expected it to be there. So perhaps misspelled it.

In JDK 1.5 this annotation will throw an error if the method is abstract in the base class.

Either it is corrected or deemed more useful in later JDKs and you can now safely provide this annotation on methods whose baseclass representations are abstract.

this annotation will also guard against some of the base class changes where a method is removed which is overridden in derived classes. You now will know that that happened.

this protection is especially important in frameworks where lot of callbacks are used like the container managed Android components.

bottom line, say @override if you expect this method to be in the base class and you are overriding it.

Android Java @override

Search for: Android Java @override

Here is what java android lang spec says

Annotation type used to mark methods that override a method declaration in a superclass. Compilers produce an error if a method annotated with @Override does not actually override a method in a superclass.

Here is a discussion on stackoverflow

Looks like this is equally applicable for Jdk 1.5 as well

Tell the compiler to see if this annotated method exists in base classes or in the inheritance hierarchy. If it is, nothing happens. If it isn't you, the programmer, have made a mistake, because you expected it to be there. So perhaps misspelled it.

As stated in that stackoverflow, this becomes more important when you rely on lot of callbacks hosted by a framework such as Android.

So your code will work even if you don't indicate @override but it is a good practice when YOU KNOW FOR sure that you are overriding it.

With or without the @Override you are not changing the run time semantics of Java!!

It will be interesting then to know what other annotations were introduced in Jdk 1.5

What are JDK 1.5 out of the box annotations?

Search for: What are JDK 1.5 out of the box annotations?

a quick summary of 1.5 features, talks about metadata quickly

Java abstract method and @Override

Search for: Java abstract method and @Override

Java 6 and @Override for abstract methods

Search for: Java 6 and @Override for abstract methods

If the base class changes and removes a method, on which you are depending, then you get an error saying that method doesn't exist anymore.

You can do this from JDK 1.6.

Here is quite a comprehensive discussion on this topic from stack overflow