Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

nazim khan
1,409 Pointshad 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

markmneimneh
14,132 PointsHello
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) .....