Search Results

Search found 1 results on 1 pages for 'user1729869'.

Page 1/1 | 1 

  • Trouble swapping values as keys in generic java BST class

    - by user1729869
    I was given a generic binary search tree class with the following declaration: public class BST<K extends Comparable<K>, V> I was asked to write a method that reverses the BST such that the values become the keys and keys become values. When I call the following method (defined in the class given) reverseDict.put(originalDict.get(key), key); I get the following two error messages from Netbeans: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: BST.put And also: no suitable method found for put(V,K) method BST.put(BST<K,V>.Node,K,V) is not applicable (actual and formal argument lists differ in length) method BST.put(K,V) is not applicable (actual argument V cannot be converted to K by method invocation conversion) where V,K are type-variables: V extends Object declared in method <K,V>reverseBST(BST<K,V>) K extends Comparable<K> declared in method <K,V>reverseBST(BST<K,V>) From what the error messages are telling me, since my values do not extend Comparable I am unable to use them as keys. If I am right, how can I get around that without changing the class given (maybe a cast)?

    Read the article

1