Java-什么是"@Override"用于? [英] Java - what is "@Override" used for?

查看:97
本文介绍了Java-什么是"@Override"用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
"@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆