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 trialJordan George
9,926 PointsWhy not use other.getCreationDate() instead of other.mCreationDate()?
So, while watching the video I was confused about why Craig was using mCreationDate() instead of getCreationDate() on the other object.
This didn't compile for me:
int dateCmp = mCreationDate.compareTo(other. mCreationDate());
if (dateCmp == 0) {
return mDescription.compareTo(other.mDescription());
}
This route compiled for me:
int dateCmp = mCreationDate.compareTo(other.getCreationDate());
if (dateCmp == 0) {
return mDescription.compareTo(other.getDescription());
}
1 Answer
Benjamin Barslev Nielsen
18,958 PointsIn your first code sample:
return mDescription.compareTo(other.mDescription());
should be
return mDescription.compareTo(other.mDescription);
since mDescription is a field and not a method. other.mCreationDate() should also be other.mCreationDate.
You can access the fields of a class from inside that class, even though it is not the "this"-instance, and therefore we can use other.mCreationDate instead of using the other.getCreationDate().
Hope this helps.
Jordan George
9,926 PointsJordan George
9,926 PointsIt does help. Thanks!