I have to create a Binary Search Tree that takes a WordCount Object as the key and the number of times that word is added to the BST as the value. In my code I have the class:
public class WordCountMap<WordCount, V> {
private TreeNode root;
private WordCount wordItem;
/**
* This is the node class
*/
private class TreeNode {
private WordCount item;
private V count;
private TreeNode left;
private TreeNode right;
TreeNode(WordCount item, V count, TreeNode left, TreeNode right) {
this.left = left;
this.right = right;
this.item = item;
}
}
public WordCountMap() {
//Create a new WordCountMap
}
/**
* Adds 1 to the existing count for a word, or adds word to the WordCountMap
* with a count of 1 if it was not already present.
*/
public void incrementCount(String word) {
wordItem = new WordCount(word);
if (root == null) {
root = new TreeNode(wordItem, wordItem.getCount(), null, null);
}
//more code below
}
}
When I try to compile the code I get the error:
WordCount extends Object declared in class WordCountMap
I tried @SuppressWarnings("rawtypes") but that still resulted in the same error.
new WordCount(...)whenWordCountis a type variable. For more targeted answers: What are you trying to do? Why do you wantWordCountas a type parameter? How do you instantiate anew WordCountMap?WordCountMap<WordCount, SOMETHING>