• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Generics confusion

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
bronco
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic