Thread: Merge Sort Help
View Single Post
  #3 (permalink)  
Old 01-29-2008, 07:56 AM
gibsonrocker800's Avatar
gibsonrocker800 gibsonrocker800 is offline
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
I'm not too good at generic programming, but i believe that E will have to be a Comparable because how else will the MergeSort know how to sort these elements. So, you have to write something like this for the class declaration:

Code:
public class MergeSort<E extends Comparable>
Saying E extends Comparable means E extends or implements the following class or interface, so in this case, we're saying E implements Comparable.
You may need to incorporate this information somewhere in your class, because i don't understand how else you can sort Objects if they can't be compared.

There are many other things you can do with these limitations. They are called wildcards.
Code:
? extends E
The specified type must be a subclass of E


Code:
? super E
The specified type must be a superclass of E

Code:
?
All types


Hope that information helps you, and anyone interested in generic programming.
__________________
//Haha javac, can't see me now, can ya?

Last edited by gibsonrocker800 : 01-29-2008 at 07:59 AM.
Reply With Quote