Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

the method compareTo(Object) is undefined for the type Object

807598Sep 25 2006 — edited Sep 25 2006
im getting an error "the method compareTo(Object) is undefined for the type Object". can anyone help??

public Comparable find(Comparable anObject)
{
for(int index = 0; index < data.size(); index++)
{
Object temp = new Object();
Object comp = data.get(index); //get an object to compare with
int n = anObject.compareTo(comp);

if(n == 0)
{
currentElement = index;
return (Comparable)comp;
}

else if(n>0)
{
int p = temp.compareTo(comp); //here is the ERROR
temp = comp;
if(p == 0)
{
currentElement = index;
}
else if(p<0)
{
currentElement = index;
return (Comparable)temp;
}
else
{
temp = comp;
currentElement = index;
}
}

}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2006
Added on Sep 25 2006
1 comment
1,260 views