I have the following Timer code below, but want to write is a lambda expression.
private void setupPollingTimmer() {
timer.scheduleAtFixedRate(new DownloadMessagesAndDisplayTask(), TIMERPERIOD,TIMERPERIOD);
}
private class DownloadMessagesAndDisplayTask extends TimerTask {
public void run() {
DownloadMessagesAndDisplay();
// timer.cancel(); //Not necessary because we call System.exit
}
}
I have looked around google and even tried () -> but it doesnt like it.
Also If there is a better version of Timer I should be using please say so.
NOTE: the supposed duplicate is not a duplicate, as its ticked answer doesn't use lambda expression. I have ticked the correct answer below.