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 - Retired Organizing Data Interfaces

nazim khan
nazim khan
1,409 Points

had Some small doubt in the code

Hi This is Nazim the code shown in video

package com.teamtreehouse;
import java.util.Date;


public class Treet implements Comparable{
private String mAuthor;
private String mDiscription;
private Date mCreationDate;

  public Treet(String author,String discription,Date creationDate){
   mAuthor= author;
    mDiscription=discription;
    mCreationDate=creationDate;
  }



public String toString(){
return "Tweet :  "+mDiscription  +"-@"+mAuthor; 
}


  //Interface Example(
@Override
 Pulic int compareTo(Object obj){
 Treet other=(Treet)obj;

   if(equals(other)){        //got doubt in this line
     return 0;
     }
   int dateCmp=mCreationDate.compareTo(other.mCreationDate)

   if(dateCmp==0){
   return mDiscription.compareTo(other.mDiscription)
   }
   return dateCmp;
 }


public String getAuthor(){
return mAuthor;
}
public String getDiscription(){
return mDiscription;
}
public Date getCreationDate(){
return mCreationDate;
} 
  public String[] getWords(){
  return mDiscription.toLowerCase().split("[^\\w@#]+");
  }

}

in Interface example block in the if Statement what we are comparing with (other)Object

1 Answer

Hello

if(equals(other)){        //got doubt in this line
     return 0;
     }

this is comparing if 'this' object  the 'other' object.   'this' is implicit here.  try 

if(this.equals(other) .....