What does @ override often mean during Android development?

Source: Internet
Author: User

@ Override is a pseudoCode, Indicates rewriting (of course not writing), but writing has the following advantages:
1. It can be used as a comment for easy reading
2. the compiler can verify for you whether the method name under @ override is all in your parent class. If not, an error is returned.
For example, if you haven't written @ override and the method name below is wrong, then your compiler can pass (it thinks this method is the method added in your subclass)

 

Example:

 

When override oncreate of the parent class, adding @ override before the method can help you check the correctness of the method. For example,Public VoidOncreate (bundle savedinstancestate ){.......} This method is correct. If you writePublic VoidOncreate (bundle savedinstancestate ){.......} In this way, the compiler returns the following error -- the method oncreate (bundle) of Type helloworld must override or implement a supertype method, to ensure that you override the oncreate method correctly. (Because oncreate should be oncreate)

If you do not add @ override, the compiler will not detect the error, but will think that you have defined a new method oncreate.

 

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.