This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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
Greenhorn

Joined: Jun 04, 2012
Posts: 29
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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7081
    
  16

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?
Artlicles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Attempting to use incompatible return type
 
Similar Threads
question related to interfaces
Error: cannot resolve symbol
Interfaces question,
Java downcasting and lists
inherit Question