0

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...

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..

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.

 - [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. 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. But I want to use List, because thats what currently the interface has. So, I believe that ant is still pointed to the old lib that has vector interface. Not sure, if this is some problem with ant or with my code. Please suggest..

codemania
  • 1,098
  • 1
  • 9
  • 26

2 Answers2

-1

You don't need the abstract modifier in an interface, and I have a hunch that is what is causing your problems. 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.

It probably used to return a Vector, but now the source you see returns a List.

I suspect you are compiling with an old version of the jar (one in which getRecordsVector() still returns a Vector) in your classpath.

NickJ
  • 9,380
  • 9
  • 51
  • 74
  • Yes, I do agree with you. Using abstract in an interface does not really make any sense. However, it is allowed. The interface I got from another team, which I don't have access to. So, the only thing I can do is to implement it. But, Do you really think that using abstract is causing the issue? Because, as I said, when I use Vector instead of List, it compiles good. – Santosh Batta Mar 14 '14 at 06:54
  • I have checked and the abstract keyword, although redundant, is not the issue. I think there's a class compatibility issue. See amended answer above. – NickJ Mar 14 '14 at 12:20
-1

What version of Java are you using? 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.

I agree with @NickJ's comment - interface methods are by nature abstract - because you must implement them in the class that implements the interface. See this posting for more information.

Community
  • 1
  • 1
mikemil
  • 1,213
  • 10
  • 21