I am having hard time understanding the best way to use generic type parameters.
Consider a priority queue implementation that implements an interface and requires all elements to be comparable of its type. The class has a constructor of with input type collection which provides initial elements. Here are a few alternatives. Can you explain differences? And provide the most general way of such declaration?
public class HeapMinPQ<E extends Comparable<E>> implements MinPQ<E> {
...
public HeapMinPQ( Collection<? extends Comparable<E>> source) {
...
}
}
public class HeapMinPQ<E extends Comparable<E>> implements MinPQ<E> {
...
public HeapMinPQ( Collection<? extends E> source) {
...
}
}
public class HeapMinPQ<E extends Comparable<? super E>> implements MinPQ<E> {
...
public HeapMinPQ( Collection<? extends Comparable<E>> source) {
...
}
}