@Override annotation in Android

Well if you understand the basic of @Override annotation it's simply metadata information that fill two purposes:

  • Describe that the method it's being override because it was defined in a interface or a extended class

  • Helps you identify correctly which method are locally declared and which are overriding since in android you will probably extends from Fragment, Activity, Services, BroadcastReceiver, etc it is a good practice that will make your code cleaner.

As for the issue that you don't see it in Java style, it is not only because it's a fairly new Feature (not that new since 2005), but because you don't override method that much in java at least not in Swing or SWT, most commonly you will find them in TableModel or when it's Servlet in the extended HttpServlet classes


You may see it rarely in old Java source code, because it's a fairly recent innovation - whereas Android code is more recent pretty much by definition.

It's a safety net, really - it tells the compiler that you're trying to override something - so please fail if the method doesn't override anything, e.g. due to a typo in the name. It's just like override being a keyword which is part of the method declaration in C#. It helps you to be explicit about what you're doing, which helps to prevent mistakes and also makes your code clearer to future readers.

Tags:

Java

Android