Use Pair as a key in a LinkedHashMap (Java)

33 views Asked by At

I have a HashMap like this

 LinkedHashMap<K, V> = new LinkedHashMap<>(); 

this map is used as cache to implement LRU (least recently used)

In this cache I want to save results from functions that have no "side-effect" so for the same input they will always produce the same output.

Im also using Bi-Functions that have <T,U,R>

T and U are generic types. Here comes the Pair<T,U> into play. How do I save a Pair like this as a key into my Hash-Map?

And can someone explain how exactly the overwriting of the equals(Obj o) and hashCode() function is supposed to help with this problem?

0

There are 0 answers