I'm refactoring an SWT project I worked on some time ago, and I would like to use Java 8, now In the current version I have something like this:
Runnable runnable = new Runnable() {
public void run() {
// do some stuff...
Display.getCurrent().timerExec(1000, this);
}
};
Display.getCurrent().timerExec(1000, runnable);
And I'm trying to use Java 8, like this:
Runnable runnable2 = () -> {
// do some stuff...
Display.getCurrent().timerExec(1000, this);
};
Display.getCurrent().timerExec(1000, runnable2);
The problem is in line:
Display.getCurrent().timerExec(1000, this);
"this" in the first code (not Java 8) is referring to the Runnable Object, in the second one is referring to the main class, indeed the error I get at compilation time is the following:
The method timerExec(int, Runnable) in the type Display is not applicable for the arguments (int, MainClass)
How can I fix this, in order to execute the timer?
EDIT: Looking in StackOverflow previous questions I found this: Lambda this reference in java
It seems is it not possible to refer to "this" in lambda, so I cannot use the SWT timer with lambda? is there a work around?