Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics confusion  RSS feed

 
KR Campbell
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've tried reading Gilad Bracha's generics tutorial, but I wondered if anyone can recommend something a bit more basic for people like me who are not so bright.

At the minute I'm struggling with the implementing compareTo(T o).
I have a FileModel class in which I wish to implement Comparable. If I declare it as
<CODE>
class FileModel implements Comparable<FileModel>
</CODE>
is it correct to write the method signature as:
<CODE>
public int compareTo(FileModel obj)
</CODE>

Regards,
Ken
 
Dave Wood
bronco
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep!

...and then you don't have to cast the parameter (or check its type) in the compareTo method. It's a beautiful thing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!