在编写Java代码时,我们真的需要@Override等吗? [英] Do we really need @Override and so on when code Java?

查看:142
本文介绍了在编写Java代码时,我们真的需要@Override等吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
何时使用Java的@Override注释,为什么?

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

我想知道在要覆盖的代码前面添加@Override的功能是什么.无论有没有,我都做了,似乎一切都进展顺利(至少对我而言).

I wonder what the functionality of adding @Override in front of the code we would like to override is. I have done with and without it, and it seemed that everything was just going well (at least, for me).

推荐答案

它不是不必要,但强烈建议使用.它可以防止您用脚射击.当编写一个您认为覆盖另一个函数但拼写错误并完全出现意外行为的函数时,它可以防止这种情况的发生.

It is not necessary, but it is highly recommended. It keeps you from shooting yourself in the foot. It helps prevent the case when you write a function that you think overrides another one but you misspelled something and you get completely unexpected behavior.

这篇关于在编写Java代码时,我们真的需要@Override等吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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