What does @Override mean in this java code?

Possible duplicate:
When do you use the @Override Java annotation and why?
Java What does @Override mean?

I was looking at the source code for the Drools Planner example, and I came across code like this:

@Override protected Solver createSolver() { XmlSolverConfigurer configurer = new XmlSolverConfigurer(); configurer.configure(SOLVER_CONFIG); return configurer.buildSolver(); } protected Solver createSolverByApi() { // Not recommended! It is highly recommended to use XmlSolverConfigurer with an XML configuration instead. SolverConfig solverConfig = new SolverConfig(); solverConfig.setSolutionClass(NQueens.class); .....TRUNCATED.... solverPhaseConfigList.add(localSearchSolverPhaseConfig); solverConfig.setSolverPhaseConfigList(solverPhaseConfigList); return solverConfig.buildSolver(); } 

As far as I understand, createSolver() and createSolverByApi() should return Solver objects when you explicitly call them.

What does @Override mean here? What is the general meaning of the term @ ?


EDIT:. Very bad; I inadvertently duplicated What does @Override?

+4
source share
5 answers

@ Java Annotations .

@Override means that the method overrides the parent class (in this case, createSolver ).

Javadoc points to @Override :

Indicates that the method declaration is intended to override the method declaration in the superclass.

This annotation is useful for checking compile time to make sure that the method you override is valid (correctly overridden).

+8
source

See the Java tutorial on annotations , as well as the Annotations Used in the Compiler section. Quick copy paste from the corresponding part

@Override - The @Override annotation tells the compiler that the element is intended to override an element declared in a superclass (overriding methods will be discussed in a lesson called Interfaces and Inheritance).

+3
source

This is called Annotation . It does not actually compile into special code, but helps to avoid errors: essentially, it indicates that the method overrides the superclass method. The absence of this annotation can lead to warnings that have this annotation, but not the superclass that has a method with the same annotation is even an error.

This avoids refactoring errors: if the method in superclass renamed, but the override is not, then it will become an error.

+2
source

This is a java annotation, in your case you would use @Override over the method to make sure that you override the method of the superclass if you use it and the method is not in the superclass because you enter its name incorrectly, for example, an error will occur during compilation.

0
source

I want to add this: declared in a superclass or method declared in an interface (since Java 6)

0
source

Source: https://habr.com/ru/post/1391204/


All Articles