In a java class i have the following code:
private class Couple<V extends Comparable<V>>{
private V v1;
private V v2;
public Couple(V v1, V v2){
this.v1 = v1;
this.v2 = v2;
}
}
I use an HashMap and i want to use keys with the Couple type. For example if i want to insert a new element in the HashMap i do the following:
HashMap<Couple<V>, Integer> map = new HashMap<Couple<V>, Integer>();
map.put(new Couple<V>(v1, v2), new Integer(10));
How should i Override the equals and hashCode methods in the Couple class using Generics?