Remove '@override' annotation

这是一个关于@Override annotation的一个讨论
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5008260

在1.6之前,@Override只对superclass起作用,
在1.6中,增加了对interface的支持,(个人感觉这样一来把override和implements 的概念混淆了,but it is better than nothing )。

下面是一些从网上找到的使用@Override的advantage:
1) You can take the advantage of compiler checking to make sure you are actually overriding a method when you think you are.
2) It makes your code easier to understand.
3) 在以前sub class override super class的某些方法, 而当super class 的相关方法改动时,sub class并不能感知到这种情况。如果使用了@Override,当super class 改变了方法定义后,sub class就能感知到,提示coder 做相应的修改。
4)其实3)这种情况不仅对 super class有用,对super type都是起一样的作用的,当interface中方法改变时,能反应到实现类, 只不过是如果改的是interface,compiler 自动会给出错误信息。



在实际应用中应该注意的一点就是:
在eclipse中,compiler 都得设置到1.6。这包括preference->java->compiler 下要改成1.6, 同时,project里的build path 里jdk 也得改成1.6。 这主要是针对同时装了1.5, 1.6,而default is 1.5这种情况的。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值