Commit

bca122c

A neat trick in Java for building an LRU cache is to override the removeEldestEntry from a LinkedHashMap such as:
public class LRUCache<K, V> extends LinkedHashMap<K, V> {
    private final int capacity;

    public LRUCache(int capacity) {
        super(capacity, 0.75f, true);
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > this.capacity;
    }
}
Do you know any such tricks in other languages?

commit bca122c