aspose file tools*
The moose likes Beginning Java and the fly likes compare Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compare" Watch "compare" New topic
Author

compare

yael buc
Greenhorn

Joined: Nov 17, 2010
Posts: 2
hello

i've got this error:
<anonymous strategies.BasicRational$1> is not abstract and does not override abstract method compare(java.lang.Object,java.lang.Object) in java.util.Comparator

for this code:

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

...................
...................

Collections.sort(foodsRef,new Comparator(){
@Override
public int compare(Food f1,Food f2) {
Double value1 = f1.getGain() / (position.distance(f1.getPosition()) + f1.getWeight());
Double value2 = f2.getGain() / (position.distance(f2.getPosition()) + f2.getWeight());
return value1.compareTo(value2);
}
}
);

return foodsRef.get(0);
}

}

can somebody explain me the problem?
thanks

yael
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

"yaeli bb", please check your private messages regarding an important administrative matter.

Thank you.
Jason Cone
Greenhorn

Joined: Jul 21, 2004
Posts: 25
Your compare method needs to specify Object arguments, rather than Food arguments.
yael buc
Greenhorn

Joined: Nov 17, 2010
Posts: 2
sorry that i didn't mention it:

import game.Food;

food is a class in my code, therefor it's an object.. am i wrong?
Alex Hurtt
Ranch Hand

Joined: Oct 26, 2010
Posts: 98
You are doing an overload, not an override. Important difference.

Also you can satisfy the compiler by using generics (assuming you are at least Java 5 or newer):


Now you're happy, compiler's happy...we're all one big happy ball of warm fuzziness.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compare