When you write an anonymous Runnable such as:
Thread producer = new Thread(new Runnable() {
@Override
public void run() {
// do something
}
});
IntelliJ suggests to replaces it with the following lambda:
Thread producer = new Thread(() -> {
// do something
}
});
which works just as fine.
How exactly does this work? In particular:
- The constructor used is still
Thread(Runnable target)
, but nothing in the lambda appears to indicate that it's a Runnable. - Why
@Override public void run()
is suddenly not needed any more?