简体   繁体   English

用ant编译错误

[英]Compile Errors with ant

I'd really tough time understanding what went wrong. 我很难理解发生了什么问题。 Beginning with this, I've an interface like this... 首先,我有一个像这样的界面...

public interface UserRecordsInterface  
{  

    public abstract List getRecordsVector()  
        throws UserExitException;  

}  

I wanted to implement this interface in my class MyRecordsClass.java like this... 我想像这样在我的类MyRecordsClass.java中实现此接口...

public class MyRecordsClass implements UserRecordsInterface{  

    private List addendaRecs             = null;  

     /** 
     * Return the list of addenda records 
     *  
     * @return List 
     */  

    public List getRecordsVector() {  
        return addendaRecs;  
    }  
}  

While compiling using ant, I got 2 errors.. 使用ant进行编译时,出现2个错误。

1 Class MyRecordsClass is not abstract and does not override the abstract method getRecordsVector() in UserRecordInterface. 1 Class MyRecordsClass is not abstract and does not override the abstract method getRecordsVector() in UserRecordInterface.

2 getRecordsVector() in MyRecordsClass cannot implement getRecordsVector() in UserRecordsInterface; attempting to use incompatible return type. 2 getRecordsVector() in MyRecordsClass cannot implement getRecordsVector() in UserRecordsInterface; attempting to use incompatible return type. getRecordsVector() in MyRecordsClass cannot implement getRecordsVector() in UserRecordsInterface; attempting to use incompatible return type.

 - [javac] found : java.util.List 
 - [javac] required: java.util.Vector 
 - [javac] public List getRecordsVector() {

Initially, the method getRecordsVector() had return type Vector in the interface. 最初,方法getRecordsVector()在接口中具有返回类型Vector。 Now, it was changed to List. 现在,它已更改为列表。 So, I've changed accordingly in my class. 因此,我在课堂上进行了相应的更改。 Now, its giving this error. 现在,它给这个错误。 If I change my class to Vector & compile, then its working fine. 如果我将类更改为Vector&compile,则可以正常工作。 But I want to use List, because thats what currently the interface has. 但是我想使用List,因为那是当前接口所具有的。 So, I believe that ant is still pointed to the old lib that has vector interface. 因此,我相信ant仍然指向具有矢量接口的旧lib。 Not sure, if this is some problem with ant or with my code. 不知道,这是否与ant或我的代码有关。 Please suggest.. 请建议..

You don't need the abstract modifier in an interface, and I have a hunch that is what is causing your problems. 您在界面中不需要abstract修饰符,而我有一种预感,那就是造成您的问题的原因。 The only place to use abstract methods is in abstract classes. 使用抽象方法的唯一位置是抽象类。

EDIT 编辑

I think it's likely that the interface has recently changed and in a separate jar. 我认为界面最近可能已更改并且在单独的jar中。

It probably used to return a Vector, but now the source you see returns a List. 它可能曾经返回一个Vector,但是现在您看到的源返回一个List。

I suspect you are compiling with an old version of the jar (one in which getRecordsVector() still returns a Vector ) in your classpath. 我怀疑您在类路径中使用的是旧版本的jar(其中一个getRecordsVector()仍返回Vector )进行编译。

What version of Java are you using? 您正在使用什么版本的Java? I am running Java7 inside IntelliJ IDEA and it didn't complain about the code - it actually compiled and I can run if I put a main method in there. 我在IntelliJ IDEA中运行Java7,它没有抱怨代码-它实际上已经编译,如果在其中放置main方法,则可以运行。

I agree with @NickJ's comment - interface methods are by nature abstract - because you must implement them in the class that implements the interface. 我同意@NickJ的评论-接口方法本质上是抽象的-因为您必须在实现接口的类中实现它们。 See this posting for more information. 有关更多信息,请参见此发布。

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

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