Extending Comparable in a generic class
<p>I am new to Java and I have a problem. I need a class to store two values, one called <code>key</code> and one called <code>value</code>. The class can store the objects, return <code>value</code> and allow comparison between two objects by comparing the key value. </p>

<pre><code>public class Entry &lt;K,V&gt; implements Comparable&lt;Entry&lt;K,V&gt;&gt; 
{
    private K key;
    private V value;

    public Entry(K key,V value)
    {
        this.key=key;
        this.value=value;
    }

    public void setValue(V value)
    {
        this.value=value;
    }

    public String toString()
    {
        return "key= "+key+" value=" +value;
    }
}
</code></pre>

<p>He is now asking me to add the <code>Comparable</code> method. I am allowed to use <code>equalsTo(Object)</code> as well. How can I implement <code>Comparable</code>? I tried</p>

<pre><code>public Comparable(k key)
{
    if (this.k &lt; k)
        return -1; 

    if (this.k &gt; k)
        return 1;

    else return 0;
}
</code></pre>

<p>but I got an error saying that I am not allowed to use <code>&gt;</code> or <code>&lt;</code>.</p>
