File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Features new in Java 8 and the fly likes @Override Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 8
Bookmark "@Override" Watch "@Override" New topic
Author

@Override

Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
I just read a book where @Override was used in a subclass.
I don't recall ever seeing that when I studied Java a few years ago - is there an additional benefit or a new requirement to use it?
Dan


Thanks in advance to all who reply,
Dan
Luke Leber
Ranch Hand

Joined: Sep 20, 2013
Posts: 41
    
    2

It's an annotation that serves as a piece of "free" meta-information that may be used by a compiler to assist in complex static analysis. To me, it also serves as a form of self-documentation.

You are in no way required to use it to produce well-formed code, however.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
It also has the benefit of catching typos in the signature of the overriding method.
If you added a tostring (with lowercase 's') method to your class without the annotation, the code would compile but you would then have to spend time working out why your toString method wasn't being called when you ran your code.
With the annotation included, you would get a compilation error and so know about the mistake much earlier.

And despite the forum you posted this in, this feature has been included since Java 1.5


Joanne
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41525
    
  53
Annotations were introduced in Java 5, so they have been around for quite a while. "Override" is one of the built-in ones that comes with the JRE, and -due to what Joanne said- I strongly recommend to get into the habit of using it.

Here's more information: http://docs.oracle.com/javase/tutorial/java/annotations/index.html


Ping & DNS - my free Android networking tools app
Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
Luke Leber wrote:It's an annotation that serves as a piece of "free" meta-information that may be used by a compiler to assist in complex static analysis. To me, it also serves as a form of self-documentation.

You are in no way required to use it to produce well-formed code, however.


Luke,
Thanks - much appreciated!
Dan
Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
Ulf Dittmer wrote:Annotations were introduced in Java 5, so they have been around for quite a while. "Override" is one of the built-in ones that comes with the JRE, and -due to what Joanne said- I strongly recommend to get into the habit of using it.

Here's more information: http://docs.oracle.com/javase/tutorial/java/annotations/index.html


Ulf,
Thanks - much appreciated!
Dan
Dan Bromberg
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
Joanne Neal wrote:It also has the benefit of catching typos in the signature of the overriding method.
If you added a tostring (with lowercase 's') method to your class without the annotation, the code would compile but you would then have to spend time working out why your toString method wasn't being called when you ran your code.
With the annotation included, you would get a compilation error and so know about the mistake much earlier.

And despite the forum you posted this in, this feature has been included since Java 1.5


Joanne,
Thanks - much appreciated!
Dan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @Override