Skip to content
Advertisement

The method compareTo(Comparable) is undefined for the type Comparable

So i am building a library as project that covers not all but most of the data structures and i found myself with this problem:

JavaScript

At rows 40 and 41 (rows 3 and 4 of method containsKeyAux) it says “The method compareTo(Comparable) is undefined for the type Comparable” and this blows my mind cause the method compareTo is actually defined inside Comparable interface only. VS Code is also showing me a warning at row 6 that says “The type parameter Comparable is hiding the type Comparable” but i am trying to make the Comparable type as generic as possible cause the key of nodes could be a String, Integer, or a different type of Object.

Advertisement

Answer

When you declare a generic like this AVLTree<Comparable,V> you have created a class with two generic types Comparable and V and Comparable has nothing to do with the interface Comparable, they just happen to have the same name.

You probably meant

JavaScript
Advertisement