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 trialvincent batteast
51,094 PointsLet's allow our BlogPost to be sorted. In this first step, just make the class implement Comparable interface, and produ
This is my error ./com/example/BlogPost.java:43: error: method does not override or implement a method from a supertype @Override ^ 1 error
Even if a delete the @Override it don't work
package com.example;
import java.util.Date;
public class BlogPost {
private String mAuthor;
private String mTitle;
private String mBody;
private String mCategory;
private Date mCreationDate;
public BlogPost(String author, String title, String body, String category, Date creationDate) {
mAuthor = author;
mTitle = title;
mBody = body;
mCategory = category;
mCreationDate = creationDate;
}
public String[] getWords() {
return mBody.split("\\s+");
}
public String getAuthor() {
return mAuthor;
}
public String getTitle() {
return mTitle;
}
public String getBody() {
return mBody;
}
public String getCategory() {
return mCategory;
}
public Date getCreationDate() {
return mCreationDate;
}
@Override
public int compareTo(BlogPost obj) {
return 1;
}
}
2 Answers
rodolphe youmbi
749 PointsHi! you should implement the Comparable interface like this : public class BlogPost implements Comparable<Object>{}; and it will pass....
Alexander Vishnyakov
8,620 Points1) Your class should implement Comparable interface --> public class BlogPost implements Comparable { } 2) To override method you should use same signature(name of method, number and TYPE of parameters). Here you take BlogPost as argument --> public int compareTo(BlogPost obj), however this is overloads method(you will find out what it is), therefore you should use this signature --> public int compareTo(Object obj) { return 1; }
vincent batteast
51,094 Pointsif I understand you right and I should use --> public int compareTo(Object obj) { return 1; } I get Bummer! Make sure that your class implements the Comparable method. in return. I know I'm missing something that is obvious but I don't see it. I gotten everything up to this point and it's driving me crazy.