File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Attempting to use incompatible return type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Attempting to use incompatible return type" Watch "Attempting to use incompatible return type" New topic
Author

Attempting to use incompatible return type

santosh batta
Ranch Hand

Joined: Jun 04, 2012
Posts: 36
Hi All,
I'd really tough time understanding interfaces & abstract classes. Begining with this, I've an interface like this...



I wanted to implement this interface in my class MyRecordsClass.java like this...



While compiling using ant, I got the error.. 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. Can you please tell me if I'm correct? If I'm wrong, what might cause this error?

Thanks in advance!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

santosh batta wrote:So, I believe that ant is still pointed to the old lib that has vector interface. Can you please tell me if I'm correct?

Yes, that must be the problem. Make sure to remove all your old *.class files and recompile everything.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8186
    
  23

santosh batta wrote:Initially, the method getRecordsVector() had return type Vector in the interface. Now, it was changed to List.

Hunh? Who did that? A Vector may be a List, but a List is most certainly NOT a Vector, so whoever did that needs to retake their Java 101 exam.

It might seem like a reasonable thing to do, but is potentially disastrous for ANY method that is expecting a Vector...and you may not find out about that until runtime.

However, I suspect Jesper's answered your current problem.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attempting to use incompatible return type