aspose file tools
The moose likes Java in General and the fly likes how to use generics with comparable Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to use generics with comparable" Watch "how to use generics with comparable" New topic
Author

how to use generics with comparable

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

I have a utility method that looks like this from Java 1.4 code. How do I get it to use generics? Or should I be using the suppression option if there is not a way?



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
If you parameterize Comparable you'll run into another problem because the compiler will warn you not to use Generic types in correlation with Arrays ...


JDBCSupport - An easy to use, light-weight JDBC framework -
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
What about...


edit: the forum software is messing up. The forum signature should read: <T extends Comparable <T>>

For a more in-depth tutorial on generics than the standard Sun tutorials have to offer, please look here: generics-tutorial
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

pete stein wrote:edit: the forum software is messing up. The forum signature should read: <T extends Comparable <T>>

Actually, just to be safe, it should be <T extends Comparable<? super T>> - this allows you to use interfaces like ScheduledFuture - which implements Comparable<Delayed> because it inherits that from Delayed.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

That makes sense. Thanks guys. I was focused on generics, I didn't think about the other "new" features.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Rob Prime wrote:Actually, just to be safe, it should be ...

Thanks for the correction and the education!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to use generics with comparable
 
Similar Threads
generics
generics
Generics
Generics