Generic Comparable gets a compiler error

106 views Asked by At

I have this code:

private class Tree<T implements Comparable<T>> {
}

I expect to put String objects into this tree, and String implements Comparable, so this looked good at first glance.

But I'm getting the error:

> expected
private class Tree<T implements Comparable<?>> {
                    ^

Suggestions?

1

There are 1 answers

4
apgp88 On

You need to use

private class Tree<T extends Comparable<T>> {
}