Hello,
I'm having a problem with a Java program that needs to implement the Comparable<E> interface. Its basically for a HuffmanNode class to construct elements of a Huffman Tree. My nodes need to be comparable to integer values (ie, the frequency of the characters in each node), but I'm having some problems writing the class header to start my problem.
A couple examples:
When my class header reads as
Code:
public class HuffmanNode implements Comparable<Integer> {
I get an error that says
Quote:
quote:HuffmanNode is not abstract and does not override abstract method compareTo(java.lang.Integer) in java.lang.Comparable
|
So I tried changing the type of comparable to another HuffmanNode. My logic was if I can compare two nodes, it should be easy enough to cast an int to a HuffmanNode. This brought about the header
Code:
public class HuffmanNode implements Comparable<HuffmanNode> {
Which brought about pretty much the same error as before:
Quote:
quote: HuffmanNode is not abstract and does not override abstract method compareTo(HuffmanNode) in java.lang.Comparable
|
Same idea again:
Header:
Code:
public class HuffmanNode implements Comparable {
produced the error
Quote:
quote:HuffmanNode is not abstract and does not override abstract method compareTo(java.lang.Object) in java.lang.Comparable
|
I then tried to make it generic:
Code:
public class HuffmanNode implements Comparable<E> {
produced:
Quote:
quote: cannot find symbol
symbol: class E
|
After this, I decided to try and change the header a bit more, so I changed implements to extends and that only produced a no interface expected error. That wasn't really a surprise, I knew it would work with an interface, but thought it was worth a try.
Anyway, to my question finally. How can I get my HuffmanNode class to implement the Comparable<E> interface? I'm using the Dr Java IDE, with Java 6, using Windows Vista.