Solve the problem of removing @ override from the android prompt

Source: Internet
Author: User

First, let's see why @ override is used.

@ Override is not a standard for Android, but an annotation added in Java 5.

Http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/override.html

@Target(value=METHOD)@Retention(value=SOURCE)public @interface Override

Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required
To generate an error message.

Since:
1.5

Indicates that this method declaration is used to override a method declaration in the superclass. If a method is declared as @ override but does not overwrite the superclass method, the compiler generates an error message.

If there is no @ override, the compiler will regard this method as a method added in your own subclass, which can be compiled.

In Android, it is very important for all android applications and activities @ override. For example, in an activity, there is a lifecycle from oncreate to ondestory, if you do not add the @ override annotation when using oncreate, it will never be called. The program can be compiled, but the application will not work normally.

Sometimes, if you import an android project, you will be prompted to remove @ override.

Because the jdk1.5 compiler overwrites the method of the parent class by default, @ override is used for description, but 1.6 has been extended to the method of the interface. For jdk5.0/1.5, the @ override annotation can only be used to override methods of superclasses, and cannot be used to implement interface methods. If it is still compiled with 1.5, an error will occur.

Solution: Change the compiler to 1.6

Right-click the project name, select properties, or find preferences in the window menu, find Java compiler, and modify the corresponding value.

TIPS:

You can automatically add overwrite and interface functions under source-> override/implement methods to ensure that the function name is correctly spelled.

Note:

In Android, there are some callback functions called automatically by the system: callbackmethods. If the program to be written is running correctly, this is not the response, it may be that @ override is not added when the callback function is overwritten and the function name is wrong.

Refer:

Http://stackoverflow.com/questions/8545540/why-override-needed-in-java-or-android

Http://www.cnblogs.com/kaierwen/archive/2012/04/19/2456594.html

Related Article

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.