Can anyone explain how does the following codes works?
public int compareTo(Object o) {
if (o instanceof Item) {
return date1.compareTo( ((Item) o).getDate2());
}
return -1;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It check that object o is an item, then compares them, the compare to function returns the values, -1, 0 and 1.
If it returns a value of 0 it means the objects are the same, if it return -1 or 1 it is saying that they are not the same.
The return at the end is the default catch, so if object o is not of that item type return no match.