Lambda Expressions in Java 8 (Part 4)

package lambdatutorial;/**
*
* @author Kasun Dissanayake
*/
public class RunnableLambda {

public static void main(String args[]){

Thread myThread = new Thread(new Runnable(){
@Override
public void run() {
System.out.println("Inside Runnable Method");
}

});
myThread.run();
}

}

NOTE: Remember, this works because Runnable has a single method. If it had more than one method, you could not have written a lambda function of that type.

package lambdatutorial;/**
*
* @author Kasun Dissanayake
*/
public class RunnableLambda {

public static void main(String args[]){

Thread myThread = new Thread(new Runnable(){
@Override
public void run() {
System.out.println("Inside Runnable Method");
}

});
myThread.run();

Thread myLambdaThread = new Thread(() -> System.out.println("Inside Lambda Runnable Method"));

myLambdaThread.run();
}

}

Functional Interfaces

--

--

--

Software Engineer at IFS R & D International (Pvt) Ltd || Former Software Engineer at Pearson Lanka || Former Associate Software Engineer at hSenid Mobile

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Guess method near drop allow.

V 1.1.5 Master Node Upgrade Procedure Guide

Create a Crypto Bot for Passive Income — Bitvavo

What New Developers Should Really Focus On

The Human Element of Software Engineering

The cover of the book “The Mythical Man-Month”

Simple Contract Event Query

Zapier and SatisMeter

Complete Rails 6 Example — Part 4

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kasun Dissanayake

Kasun Dissanayake

Software Engineer at IFS R & D International (Pvt) Ltd || Former Software Engineer at Pearson Lanka || Former Associate Software Engineer at hSenid Mobile

More from Medium

Factory Method pattern in Java

Exceptions in Java

Java Theory and Practice

Comparing Arrays.sort() and Collections.sort() in Java