The role of @Override

Source: Internet
Author: User

@Override is pseudo-code, which means rewriting (not writing, but some Ides will report warning), but the following benefits are written:
1, can be used as a comment, easy to read;
2, the compiler can give you to verify @override the following method name is all in your parent class, if there is no error. For example, if you do not write @override, and your next method name is wrong, then your compiler can be compiled through, because the compiler thought this method is your subclass of the method of adding itself.
3, for patients with obsessive-compulsive disorder has a good thing is to reduce the warning! when NetBeans detects a overwrite behavior, it prompts warning! This makes me very uncomfortable, so every time I write to cover the method to see if there is no hint warning, if there is, I wrote the right, if not it is wrong! Feel check spelling until appear warning, and then add a @override in front (I also don't have to toss, who let me is a virgo!) )。


Example: When overriding the paintcomponent of a parent class, adding a @override system in front of the method can help you check the correctness of the method.
@Override
public void PaintComponent(Graphics g)

{.......}
This notation is correct if you write:

@Override
public void Paintcomponet(Graphics g)
{.......}
The compiler will report the following error: The method paintcomponent must override or implement a Supertype method, This ensures that you are correctly overriding the Paintcomponent method (because paintcomponet should be paintcomponent). And if you don't add @override, the compiler will not detect an error, but will think you have defined a new method for the subclass: Paintcomponet

The role of @Override

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.