Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1543982
  • 博文数量: 237
  • 博客积分: 5139
  • 博客等级: 大校
  • 技术积分: 2751
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 14:48
文章分类

全部博文(237)

文章存档

2016年(1)

2012年(4)

2011年(120)

2010年(36)

2009年(64)

2008年(12)

分类: 嵌入式

2011-06-15 21:39:26

在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这种情况的。
阅读(3573) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~