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 trialAngad Singh
1,200 PointscompareTo
public int compareTo(Object o){ Treet other=(Treet)o; ....... } why do we need to explicitly type cast object 'o' to Treet when it is already referenced to treet object passed to its as an parameter??
1 Answer
Benjamin Barslev Nielsen
18,958 PointsIt is not referenced as a Treet object in the method signature:
public int compareTo(Object o)
The parameter is defined to have type Object, and therefore the cast to Treet is needed.