user2860442
user2860442

Reputation: 11

Why is my generic implementation not working? (extends Comparable<? super T>>)

I am implementing a Binary Search Tree with BinaryNode<T> that holds the information. In my tree class I have this line of code:

public class BST<T> implements BSTInterface<T extends Comparable<? super T>>

This is causing many errors such as:

BST.java:10: error: > expected
public class BST<T> implements BSTInterface<T extends Comparable<? super T>>
                                          ^
BST.java:10: error: <identifier> expected
public class BST<T> implements BSTInterface<T extends Comparable<? super T>>
                                                                           ^

I am not sure why this isn't working because that line of code works for my interface. Any help would be much appreciated! I am probably making some stupid mistake.

Upvotes: 0

Views: 237

Answers (1)

Dawood ibn Kareem
Dawood ibn Kareem

Reputation: 79847

I think you intended to write

public class BST<T extends Comparable<? super T>> implements BSTInterface<T>

You have to put the bounds on T at the first mention of T.

Upvotes: 11

Related Questions