| Author |
Comparable and generics
|
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
|
|
Hi all, How is it logically correct to compare a sub class with a super class? I read in a book that -
It isn�t necessary that T be comparable to exactly itself. All that�s required is that T be comparable to one of its supertypes.
and that is why comparable is defined as Comparable<? super T> Thanks
|
Cheers!
RSR
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8263
|
|
Originally posted by rakesh sugirtharaj: How is it logically correct to compare a sub class with a super class?
Would it make sense to compare two different ways to represent the same thing, like a date on the Gregorian Calendar to a date on the Julian Calendar? I'd think so. Presumably they'd have the same base class and that would indicate the relationship between the derived classes: they both represent time.
Originally posted by rakesh sugirtharaj: Comparable<? super T>
I don't see it. Perhaps your book does that to drive the point home?
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
rakesh sugirtharaj
Ranch Hand
Joined: Dec 16, 2007
Posts: 151
|
|
I actually found that statement in a pdf download from Sun site. Generics tutorial by Gilad Bracha.
|
 |
Daniel Chemko
Ranch Hand
Joined: Feb 27, 2008
Posts: 32
|
|
You sparked my interest in what the differences would really be, so I wrote a test app to play around with the concept. Anywhere the file doesn't compile, we can see the limitations of each type of passing in a comparator
|
 |
Dr Cheaper
Greenhorn
Joined: Aug 11, 2008
Posts: 1
|
|
|
You can also compare compare generics.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
"Dr Cheaper", Please read your private messages regarding an important announcement. Thank you, Rob
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Comparable and generics
|
|
|