简体   繁体   English

覆盖注解和 JDK 1.5

[英]Override annotation and JDK 1.5

I'm using JDK 1.5, here is my class:我使用的是 JDK 1.5,这是我的课程:

public final class Account implements ICAccount

{
//...
   @Override
   public ObjectID getId()
   {
      return new ObjectID(id);
   }
//...
}

Account overrides method getId() from ICAccount Account覆盖ICAccount getId()方法

But compilation fails.但是编译失败。

Account.java  method does not override a method from its superclass  

If i'm using JDK 1.6 the compilation succeeds.如果我使用的是 JDK 1.6,则编译成功。

In documentation to @Override annotation I see在@Override 注释的文档中,我看到

Since:
1.5  

What is the problem?问题是什么?

The Override annotation is only used when overriding methods from classes in java 1.5. Override 注释仅在从 java 1.5 中的类中覆盖方法时使用。 It also works for implementation of interface methods from Java 1.6.它也适用于从 Java 1.6 实现接口方法。

In Java 1.5 the @Override annotation is not allowed for methods that implement an interface method, only for methods that in fact override methods from a superclass.在 Java 1.5 中, @Override注释不允许用于实现接口方法的方法,仅用于实际上覆盖超类方法的方法。 This changed in Java 1.6.这在 Java 1.6 中发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM