Method declaration I don't understand (I think)

Ok, here is the declaration:

publicstatic <Eextends Comparable><?super E>>int search(E[] a, E value)

Now, like I say I'm not entirely sure what this means, but this is what I think it means - could someone tell me if I am correct or not.

Does it mean that we have a class E, that at the moment doesn't extend Comparable, but in order to use the compareTo method, which is used within the method I listed above, we have to declare it as extending Comparable in the method declaration?

[694 byte] By [nealbo101a] at [2007-11-27 4:06:22]
# 1
Google Java Generics. Here is a link but www.javasoft.com is apparently down: http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
jbisha at 2007-7-12 9:11:28 > top of Java-index,Java Essentials,New To Java...
# 2

What is means is that in order the method can work, the unknown parameter class E has to implement Comparable. I guess the method needs to compare objects with each other. That is why you have to declare that it extends Comparable.

But now the problem is now that Comparable comes in many flavours: it's also parametrised. How should its parameter be chosen? You only want to compare objects of E with each other, so would "Comparable<E>" work? It would, but it would be too restrictive: instances of E are comparable if any super class of E implements Comparable. This is how you get "E extends Comparable<? super E>": E or one of its super classes should to implement Comparable<D> where D is either E or a super class of E.

jsalonena at 2007-7-12 9:11:28 > top of Java-index,Java Essentials,New To Java...
# 3

That's it. Sounds convoluted, but that's the type used for [url=http://java.sun.com/javase/6/docs/api/java/util/Collections.html#sort(java.util.List)]Collection.sort[/url].

If I ever need to summon up a definition like that in my code, I go see how they did it in the collection framework.

DrLaszloJamfa at 2007-7-12 9:11:28 > top of Java-index,Java Essentials,New To Java...