Reputation: 75
Hi I wrote simple code for Comparable interface As below
import java.util.*;
class Gaurav123 implements Comparable<Gaurav123>
{
String title;
Gaurav123()
{
}
Gaurav123(String title)
{
this.title=title;
}
public int compareTO(Gaurav123 b)
{
return title.compareTo(b.title);
}
}
public class Gaurav1234
{
public static void main(String [] args)
{
Gaurav123 g1=new Gaurav123("gaurav");
Gaurav123 g2=new Gaurav123("Surbhi");
Gaurav123 g3=new Gaurav123("Kailash");
TreeSet<Gaurav123>ts=new TreeSet<Gaurav123>();
ts.add(g1);
ts.add(g2);
ts.add(g3);
}
}
But I am getting this error
C:\Users\gakaushik\Desktop>javac Gaurav1234.java
Gaurav1234.java:2: Gaurav123 is not abstract and does not override abstract meth
od compareTo(Gaurav123) in java.lang.Comparable
class Gaurav123 implements Comparable<Gaurav123>
^
1 error
Any Idea what is the issue. I followed all Comparable interface protocols
Upvotes: 0
Views: 67
Reputation: 20736
Java is fully case sensitive... Your method is called
compareTO
It should be called
compareTo
However, next time be sure to read the error message carefully, it is usually a good hint what to look at... Another good thing to do before asking a question is to copz and paste the error into any search engine you find (even at Stackoverflow)
Upvotes: 2