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