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 trial

Java Java Data Structures Organizing Data Comparable

nikhil davasam
nikhil davasam
2,182 Points

why is it not working

it says shows a error with override pls help

com/example/BlogPost.java
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(Object obj) {
    return 1;
  }
}

2 Answers

Patrik Horváth
Patrik Horváth
11,110 Points

Hi, as Questiontell use Implements :) so you need implement Comparable Interface and there is no reason put @Override to complareTo method yet :) why ? because your method doesnt do anything just returning 1, but in future when you done your method it should be there :)

classs ... implements Comparable {

}
nikhil davasam
nikhil davasam
2,182 Points

its not working.there are compiler errors telling that unexpected type

Patrik Horváth
Patrik Horváth
11,110 Points

i m so sorry to telling this but this WORKS, tryed it in this challange and it works perfect, so problem is you and you HAVE to go true Course again because i think you dont underestend INTERFACE concept :) and Comparable, why ? because soon you will use for example SORTABLE, so you neeed underestend this

just my opinion ( never go next if you dont underestend! it can takes mounths but its Okey just ask someone who know whot is it and can explain to you if this course is not enought ) - i dont taked this course here because i already know it so i m not sure if its good explained :/

Tony Gemenie
Tony Gemenie
3,781 Points

Hey Nikhil!

At the top of the class you need to implement the Interface. All you need is where you declared your class {public class BlogPost} add in {implements Comparable}. Ez breezy.