This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attempting to use incompatible return type

 
santosh batta
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15359
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic