aitchnyu aitchnyu - 5 months ago 12
Java Question

What does @Override mean in this java code?


Possible Duplicate:

When do you use Java's @Override annotation and why?

Java, What does @Override mean?




I was checking out Drools Planner example source code 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()
are supposed to return Solver objects when you explicitly call them.

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




EDIT: My very bad; I inadvertently duplicated Java, What does @Override mean?

Answer

The @ is Java Annotations.

The @Override means that the method is overriding the parent class (in this case createSolver).

The Javadoc states for @Override:

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

This annotation is useful for compile-time checking to verify that the method you're overriding is valid (overridden correctly).

Comments