Replace Anonymous inner classes with Lambdas.
public class ReplaceAnonymousWithLambda {
public static void main(String[] args) {
//Using Runnable anonymour inner class
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("run() executed from Runnable Anonymous inner class");
}
});
//-----------------(A)
thread.run();
//Using Lambda function as a replacement for the Runnable anoynymous class
thread = new Thread(()->System.out.println("contents as in run() using Lambda exp"));
//-----------------(B)
thread.run();
}
}
No comments:
Post a Comment