| Author |
how to use generics with comparable
|
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26192
|
|
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
|
|
|
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!
|
 |
 |
|
|
subject: how to use generics with comparable
|
|
|