Remove '@override' annotation

来源:互联网 发布:小型软件课程设计 编辑:程序博客网 时间:2024/05/21 21:46

 

 

 

 

本文出自:http://blog.csdn.net/Olive_HMS/archive/2010/03/18/5392402.aspx

 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 0
原创粉丝点击