使用ant的java编译错误
我真的很难理解出了什么问题。从这里开始,我有一个这样的界面
public interface UserRecordsInterface
{
public abstract List getRecordsVector()
throws UserExitException;
}
我想在我的类MyRecordsClass中实现这个接口。像这样的java
public class MyRecordsClass implements UserRecordsInterface{
private List addendaRecs = null;
/**
* Return the list of addenda records
*
* @return List
*/
public List getRecordsVector() {
return addendaRecs;
}
}
在使用ant编译时,我遇到了两个错误
1Class MyRecordsClass is not abstract and does not override the abstract method getRecordsVector() in UserRecordInterface.
2getRecordsVector() 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() {
最初,方法getRecordsVector()
在接口中有返回类型向量。现在,它被改为列表。所以,我在班上也做了相应的改变。现在,它给出了这个错误。如果我将我的类更改为Vector&;编译,然后它的工作良好。但我想使用List,因为这就是当前界面的功能。所以,我相信ant仍然指向具有向量接口的旧库。不确定,这是否是ant或我的代码的问题。请建议
# 1 楼答案
您使用的是什么版本的Java?我在IntelliJ IDEA中运行Java7,它没有抱怨代码——它实际上已经编译,如果我在其中放入一个main方法,我就可以运行它
我同意@NickJ的评论——接口方法本质上是抽象的——因为必须在实现接口的类中实现它们See this posting for more information.
# 2 楼答案
在接口中不需要
abstract
修饰符,我有一种预感,这就是导致问题的原因。使用抽象方法的唯一地方是抽象类编辑
我认为很可能是接口最近发生了变化,并且在一个单独的jar中
它可能用于返回向量,但现在您看到的源返回一个列表
我怀疑您是在使用旧版本的jar(其中
getRecordsVector()
仍然在类路径中返回Vector
)进行编译的