Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrian Pedigo
26,783 PointsCant override compareTo ?
Here is the code that is causing the complier error of: method does not override from a supertype. @Override Public int compareTo(Object obj) { }
2 Answers
Craig Dennis
Treehouse TeacherDoes the class implement Comparable
?
Brian Pedigo
26,783 PointsThank you sir that was the problem! I forgot to implement comparable in the class header. thanks for your help!
Alex Sidlinskiy
9,975 PointsI get the same error on compareTo() method override. Here's what my code looks like.
@Override
public int compareTo(Object obj){
Treet other = (Treet) obj;
if(equals(other)){
return 0;
}
int dateCmp = mCreationDate.compareTo(other.mCreationDate);
if(dateCmp == 0){
return mDescription.compareTo(other.mDescription);
}
return dateCmp;
}
Jeffery Briggette
Courses Plus Student 5,567 PointsAdding:
package com.teamtreehouse;
import java.util.Date;
public class Treet implements Comparable { // Awesome code here....
Should solve the problem.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI'm not sure what to suggest but have you tried changing
Public
topublic
?Steve.