At some point java.lang.Override
started to be available for use with implementations of methods declared in interfaces. I'm pretty sure there was a time when it just worked for overrides of methods defined in superclasses.
在某些时候,java.lang.Override开始可用于接口中声明的方法的实现。我很确定有一段时间它只适用于超类中定义的方法的覆盖。
How can I find out when (i.e. at which version) this change happened?
我怎样才能知道这种变化发生的时间(即哪个版本)?
3 个解决方案
#1
Use of the @Override
annotation on methods that are implemented from interfaces and not overridden from a superclass is a new feature in Java 6. See @Override specification changes in Java 6:
对从接口实现而不是从超类重写的方法使用@Override注释是Java 6中的一项新功能。请参阅Java 6中的@Override规范更改:
Between Java 5 and Java 6 changes to the specification of @Override have been made. In Java 6 it is possible to add the @Override annotation to methods that implement methods of an interface which is not allowed in Java 5.
在Java 5和Java 6之间已经对@Override的规范进行了更改。在Java 6中,可以将@Override注释添加到实现Java 5中不允许的接口方法的方法中。
I noticed the difference when a friend told me that he had to remove all the @Override annotations to make his Java 6 project compile with Java 5.
当一位朋友告诉我他必须删除所有@Override注释以使他的Java 6项目使用Java 5编译时,我注意到了区别。
The interesting thing is that there is no documentation about this change. The API specification of @Override is exactly the same in both Java versions. I found out that this was forgotten by Sun developers. Peter Ahé, a former developer at Sun, calls it the @Override Snafu.
有趣的是,没有关于此更改的文档。 @Override的API规范在两个Java版本中完全相同。我发现Sun开发人员忘记了这一点。 Sun的前开发人员PeterAhé将其称为@Override Snafu。
#2
I don't know how you'd find this out, but it happened between 5 and 6. (i.e. it's forbidden in 5 but accepted in 6.)
我不知道你是怎么发现的,但它发生在5到6之间(即它在5中被禁止但在6中被接受)
#3
You cannot "officially" find out because someone at Sun messed up and did not update the specification in the API doc of java.lang.Override
when the implementation was changed, and apparently changing the specification after the release is not allowed.
您无法“正式”发现,因为Sun的某些人搞砸了并且在更改实现时没有更新java.lang.Override的API文档中的规范,并且显然在不允许发布后更改规范。
#1
Use of the @Override
annotation on methods that are implemented from interfaces and not overridden from a superclass is a new feature in Java 6. See @Override specification changes in Java 6:
对从接口实现而不是从超类重写的方法使用@Override注释是Java 6中的一项新功能。请参阅Java 6中的@Override规范更改:
Between Java 5 and Java 6 changes to the specification of @Override have been made. In Java 6 it is possible to add the @Override annotation to methods that implement methods of an interface which is not allowed in Java 5.
在Java 5和Java 6之间已经对@Override的规范进行了更改。在Java 6中,可以将@Override注释添加到实现Java 5中不允许的接口方法的方法中。
I noticed the difference when a friend told me that he had to remove all the @Override annotations to make his Java 6 project compile with Java 5.
当一位朋友告诉我他必须删除所有@Override注释以使他的Java 6项目使用Java 5编译时,我注意到了区别。
The interesting thing is that there is no documentation about this change. The API specification of @Override is exactly the same in both Java versions. I found out that this was forgotten by Sun developers. Peter Ahé, a former developer at Sun, calls it the @Override Snafu.
有趣的是,没有关于此更改的文档。 @Override的API规范在两个Java版本中完全相同。我发现Sun开发人员忘记了这一点。 Sun的前开发人员PeterAhé将其称为@Override Snafu。
#2
I don't know how you'd find this out, but it happened between 5 and 6. (i.e. it's forbidden in 5 but accepted in 6.)
我不知道你是怎么发现的,但它发生在5到6之间(即它在5中被禁止但在6中被接受)
#3
You cannot "officially" find out because someone at Sun messed up and did not update the specification in the API doc of java.lang.Override
when the implementation was changed, and apparently changing the specification after the release is not allowed.
您无法“正式”发现,因为Sun的某些人搞砸了并且在更改实现时没有更新java.lang.Override的API文档中的规范,并且显然在不允许发布后更改规范。