I try to extend the AbstractTreap class in my Treap class with the generics.
I downloaded the TreapNode and AbtractTreap file and try to implement the Treap class as some exercise.
The result should be a Treap like here: https://www.geeksforgeeks.org/treap-a-randomized-binary-search-tree/
public class Treap<E> extends AbstractTreap<E>
public final class TreapNode<E extends Comparable<? super E>>
implements Comparable<TreapNode<E>>, java.util.Comparator<TreapNode<E>>
public abstract class AbstractTreap<E extends Comparable<? super E>>
Error:
Bound mismatch: The type E is not a valid substitute for the bounded parameter > of the type AbstractTreap
AbstractTreap
has a generic parameter that is a Comaparable
. If you extend it and pass that parameter, you must make sure it stands for at least the same bounds (if not more restrictive). Eg:
public class Treap<E extends Comparable<? super E>> extends AbstractTreap<E>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.