I want to perform a delayed operation on a map, so I am using Timer
, to which I am passing a TimerTask
and a delay in milliseconds:
timer.schedule(new TimerTask() {
public void run() {
tournaments.remove(id);
}
}, delay);
This is some sort of primitive cache-like functionality where I set an expiration time on a new resource that was just created.
I thought I could do that using lambdas, just like follows:
times.schedule(() -> tournaments.remove(id), delay);
But the compiler says this cannot be done. Why? What am I doing wrong? Could I use lambdas to achieve more concise code or it's simply not possible here and I should stick to an anonymous class?