Let's first look at a code snippet:
public class CommonEaoImpl extends BasicEao implements ICommonEao {@Overridepublic void save(Object entity) {em.persist(entity);}@Overridepublic
void saveList(List
entitys) {for (Object entity : entitys) {em.persist(entity);}}}
From the Code, there is no error, but the error is as follows:
The method save(Object) of type CommonEaoImpl must override a superclass method
The Code does not need to be explained more. A simple translation of errors: the parent class must have a save method before the subclass can be rewritten. The current situation is that although BasicEao. java does not have the save method, there is a save statement in ICommonEao:
void save(Object entity);
It is easy to solve this problem simply. Remove @ Override from the subclass to compile the code correctly. But I think we can think a little more: Why can we just delete it?
After checking, we found that the error is not in the code, but in jdk, the code can be correctly compiled in jdk 1.6, but in jdk, the @ Override error is reported because: in jdk1.5, @ Override applies only to class inheritance, but not to interface implementation. In jdk1.6, @ Override supports both implementation and inheritance.
So now there are two solutions:
I declared save in the ICommonEao interface to change jdk to 1.6 in BasicEao of the parent class. In order to confirm this, I also went to the API documentation (jdk1.5, jdk1.6) on the official website, this difference is not shown in official documents. Both are:
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.
After learning English during this period, I think you can try to translate it.