I want to upgrade this code to use a lambda expression:
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
missileX = ufoX;
resetRecent();
waitForUfoTimer = false;
}
}, randomize(20000, 18000));
I try it this way but it doesn't compile:
Handler handler2 = new Handler(Looper.getMainLooper());
handler2.postDelayed(Runnable task = () -> {
missileX = ufoX;
resetRecent();
waitForUfoTimer = false;
}
}, randomize(20000, 18000));
Where are some instructions so that I can learn how to do it? It is preposterous that I must guess the syntax.
You don't have to declare a variable to assign to the lambda. This is enough :
Handler handler2 = new Handler(Looper.getMainLooper());
handler2.postDelayed(() -> {
missileX = ufoX;
resetRecent();
waitForUfoTimer = false;
}
, randomize(20000, 18000));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With