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 Interfaces

Brian Pedigo
Brian Pedigo
26,783 Points

Cant 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) { }

I'm not sure what to suggest but have you tried changing Public to public?

Steve.

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Does the class implement Comparable?

Brian Pedigo
Brian Pedigo
26,783 Points

Thank you sir that was the problem! I forgot to implement comparable in the class header. thanks for your help!

Alex Sidlinskiy
Alex Sidlinskiy
9,975 Points

I 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
PLUS
Jeffery Briggette
Courses Plus Student 5,567 Points

Adding:

package com.teamtreehouse;

import java.util.Date;

public class Treet implements Comparable { // Awesome code here....

Should solve the problem.