I have the following anonymous Runnable
implementation.
Runnable cronTask = new Runnable() {
@Override
public void run() {
// do something
}
};
IntelliJ suggests that I replace it with a lambda expression. What shortcut can I use to convert it? What is the syntax if I would like to do it manually?
Edit: The lambda expression for this Runnable is:
Runnable cronTask = () -> {
// do something
};
Alt + Enter is good way to change each one individual
but there is away to change all lambda expression across app
Ctrl + Shift+ Alt + I
source site
How we can use it in our Android Studio and lambda expression:
just write replace lambda as Inspection name called
anonymous type can be replaced with lambda
List of occurrence will appear change each one manually
Tutorial Video
Let IntelliJ do the lifting here; you can invoke Alt + Enter (or Option + Return on Mac) to allow IntelliJ to replace it with a lambda expression.