Java 8 removes the burden of Anonymous class

if you are a java programmer so you know what is the Anonymous class

below is the example of it,before some time this was useful for programmer but now it is like a burden to a programmer,just to print a single line using sysout we have  7 line of bioler plate code

Runnable r1=new Runnable() {
public void run() {
System.out.println(“inside run method”);


java 8 releases you from this bioloer plate code

Runnable task3 = () ->      System.out.println(“inside run method”);

() -> is the lambda expression the square bracket indicate to compiler that this method doesn’t take any argument so it is left without parameter and then -> shows that code should be executed after these.

And you can use { } to run multiple line statement

Runnable task3 = () ->   {  System.out.println(“inside run method”);

System.out.println(“inside run method”);


This is just the starting be connect to learn more cool thing about java 8 like stream,map



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s