Java-什么是"@Override"用于? [英] Java - what is "@Override" used for?
问题描述
可能重复:
"@Override"是什么?在Java中有?
Possible Duplicate:
What's “@Override” there for in java?
到目前为止,我从未将"@Override"放在方法之前.我看到了一些代码示例,但我不了解它的实用程序.我希望得到一些解释.
I've never put "@Override" before a method until now. I see some code examples with it, but I don't understand its utility. I'd love some explanation.
非常感谢,
JDelage
推荐答案
首先,您不能使用@Override
注释 class .此注释表明方法声明旨在覆盖超类中的方法声明.
First, you can't annotate a class with @Override
. This annotation indicates that a method declaration is intended to override a method declaration in a superclass.
您不必注释覆盖方法,但是如果使用此注释并且注释的方法没有覆盖超类方法,则编译器将生成错误消息.
You don't have to annotate overriding methods but if you use this annotation and your annotated method does not override a superclass method, then the compiler will generate an error message.
这篇关于Java-什么是"@Override"用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!