English 中文(简体)
The What does @Override mean in this java Code? [复制]
原标题:What does @Override mean in this java code? [duplicate]
  • 时间:2012-01-16 07:33:13
  •  标签:
  • java
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
When do you use Java s @Override annotation and why?
Java, What does @Override mean?

我正在检查Drools Planner,例如来源代码。

@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();
}

就我所知,createSolver()和createSolverByApi()应当返还。 当你明确称呼它们时,可以撒谎。

<代码>@ 此处指的是超低温带/代码。 <>>这一术语的一般含义是什么?


http://www.un.org。 我很坏;我无意中重复了。 @Override的意思是什么?

最佳回答

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.

这种说明有助于进行编辑时检查,以核实你重新压倒一切的方法是有效的(掩盖正确)。

问题回答

See the Java tutorial about annotations, and there the Annotations used by the compiler section. A quick copy-paste from the relevant part

@Override - @Override annotation informs汇编者,该要素意在超越超级类别中宣布的内容(将在题为“接口和遗产”的教训中讨论过渡方法)。

This is called an Annotation. It is actually not compiled into special code, but it helps avoiding errors: essentially, it indicates that the method overrides a method of a superclass. Not having this annotation can cause warnings, having this annotation but no superclass that has a method with the same annotation is even an error.

这避免了重复的错误:如果将<代码>超级类别<>/代码>中的方法重新命名,而不是倒数,那就会变成错误。

This is java annotation , in your case you would use @Override above a method to be sure that you are overriding a super class method , if you use it and the method is not in the super class because you type it name wrong for example an error will occur at compile time .

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





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签