Meaning of lambda () -> in Java
Clash Royale CLAN TAG#URR8PPP
up vote
15
down vote
favorite
I am looking at the following Stack Overflow answer:
How to change Spring's @Scheduled fixedDelay at runtime
And in the code there is the following line:
schedulerFuture = taskScheduler.schedule(() -> , this);
I would like to know what the lambda () ->
means in that code. I need to write it without using lambdas.
java lambda java-8 java-7 java-9
add a comment |Â
up vote
15
down vote
favorite
I am looking at the following Stack Overflow answer:
How to change Spring's @Scheduled fixedDelay at runtime
And in the code there is the following line:
schedulerFuture = taskScheduler.schedule(() -> , this);
I would like to know what the lambda () ->
means in that code. I need to write it without using lambdas.
java lambda java-8 java-7 java-9
25
It's aRunnable
that does nothing.
– ernest_k
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
3
without lambda, you would need to pass an anonymous Runnable with empty body, likenew Runnable() @Override public void run()
– Alex Salauyou
yesterday
add a comment |Â
up vote
15
down vote
favorite
up vote
15
down vote
favorite
I am looking at the following Stack Overflow answer:
How to change Spring's @Scheduled fixedDelay at runtime
And in the code there is the following line:
schedulerFuture = taskScheduler.schedule(() -> , this);
I would like to know what the lambda () ->
means in that code. I need to write it without using lambdas.
java lambda java-8 java-7 java-9
I am looking at the following Stack Overflow answer:
How to change Spring's @Scheduled fixedDelay at runtime
And in the code there is the following line:
schedulerFuture = taskScheduler.schedule(() -> , this);
I would like to know what the lambda () ->
means in that code. I need to write it without using lambdas.
java lambda java-8 java-7 java-9
java lambda java-8 java-7 java-9
edited 15 hours ago


Boann
35.6k1184116
35.6k1184116
asked yesterday
Aliuk
303517
303517
25
It's aRunnable
that does nothing.
– ernest_k
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
3
without lambda, you would need to pass an anonymous Runnable with empty body, likenew Runnable() @Override public void run()
– Alex Salauyou
yesterday
add a comment |Â
25
It's aRunnable
that does nothing.
– ernest_k
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
3
without lambda, you would need to pass an anonymous Runnable with empty body, likenew Runnable() @Override public void run()
– Alex Salauyou
yesterday
25
25
It's a
Runnable
that does nothing.– ernest_k
yesterday
It's a
Runnable
that does nothing.– ernest_k
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
3
3
without lambda, you would need to pass an anonymous Runnable with empty body, like
new Runnable() @Override public void run()
– Alex Salauyou
yesterday
without lambda, you would need to pass an anonymous Runnable with empty body, like
new Runnable() @Override public void run()
– Alex Salauyou
yesterday
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
35
down vote
accepted
Its a Runnable
with an empty run
definition. The anonymous class representation of this would be:
new Runnable()
@Override public void run()
// could have done something here
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is() ->
and notRunnable.noop
, from one of the Java designers).
– yshavit
15 hours ago
add a comment |Â
up vote
2
down vote
Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code. They have no access modifier(private, public or protected), no return type declaration and no name.
Lets take a look at this example.
(int a, int b) -> return a > b
In your case, you can do something like below:
schedulerFuture = taskScheduler.schedule(new Runnable()
@Override
public void run()
// task details
, this);
add a comment |Â
up vote
1
down vote
For lambdas:
Left side is arguments, what you take. Enclosed in ()
are all the arguments this function takes
->
indicates that it's a function that takes what's on the left and passes it on to the right for processing
Right side is the body - what the lambda does. Enclosed in is everything this function does
After you figure that out you only need to know that that construction passes an instance of matching class (look at what's the expected argument type in the schedule()
call) with it's only method doing exactly the same as the lambda expression we've just analyzed.
add a comment |Â
up vote
-1
down vote
Lambda expressions basically express instances of functional interfaces.
In a way Lambda expression will be: (lambda operator params) -> body
() -> System.out.println("This means Lambda expression is not taking any parameters");
(p) -> System.out.println("Lambda expression with one parameter: " + p);
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
35
down vote
accepted
Its a Runnable
with an empty run
definition. The anonymous class representation of this would be:
new Runnable()
@Override public void run()
// could have done something here
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is() ->
and notRunnable.noop
, from one of the Java designers).
– yshavit
15 hours ago
add a comment |Â
up vote
35
down vote
accepted
Its a Runnable
with an empty run
definition. The anonymous class representation of this would be:
new Runnable()
@Override public void run()
// could have done something here
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is() ->
and notRunnable.noop
, from one of the Java designers).
– yshavit
15 hours ago
add a comment |Â
up vote
35
down vote
accepted
up vote
35
down vote
accepted
Its a Runnable
with an empty run
definition. The anonymous class representation of this would be:
new Runnable()
@Override public void run()
// could have done something here
Its a Runnable
with an empty run
definition. The anonymous class representation of this would be:
new Runnable()
@Override public void run()
// could have done something here
edited 18 hours ago
dun
295
295
answered yesterday


nullpointer
30.4k1054127
30.4k1054127
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is() ->
and notRunnable.noop
, from one of the Java designers).
– yshavit
15 hours ago
add a comment |Â
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is() ->
and notRunnable.noop
, from one of the Java designers).
– yshavit
15 hours ago
2
2
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is
() ->
and not Runnable.noop
, from one of the Java designers).– yshavit
15 hours ago
Related: stackoverflow.com/a/26553481/1076640 (contains commentary on why the idiom is
() ->
and not Runnable.noop
, from one of the Java designers).– yshavit
15 hours ago
add a comment |Â
up vote
2
down vote
Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code. They have no access modifier(private, public or protected), no return type declaration and no name.
Lets take a look at this example.
(int a, int b) -> return a > b
In your case, you can do something like below:
schedulerFuture = taskScheduler.schedule(new Runnable()
@Override
public void run()
// task details
, this);
add a comment |Â
up vote
2
down vote
Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code. They have no access modifier(private, public or protected), no return type declaration and no name.
Lets take a look at this example.
(int a, int b) -> return a > b
In your case, you can do something like below:
schedulerFuture = taskScheduler.schedule(new Runnable()
@Override
public void run()
// task details
, this);
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code. They have no access modifier(private, public or protected), no return type declaration and no name.
Lets take a look at this example.
(int a, int b) -> return a > b
In your case, you can do something like below:
schedulerFuture = taskScheduler.schedule(new Runnable()
@Override
public void run()
// task details
, this);
Lamda expression is an anonymous function that allows you to pass methods as arguments or simply, a mechanism that helps you remove a lot of boilerplate code. They have no access modifier(private, public or protected), no return type declaration and no name.
Lets take a look at this example.
(int a, int b) -> return a > b
In your case, you can do something like below:
schedulerFuture = taskScheduler.schedule(new Runnable()
@Override
public void run()
// task details
, this);
edited yesterday
answered yesterday


Prashant Goswami
1035
1035
add a comment |Â
add a comment |Â
up vote
1
down vote
For lambdas:
Left side is arguments, what you take. Enclosed in ()
are all the arguments this function takes
->
indicates that it's a function that takes what's on the left and passes it on to the right for processing
Right side is the body - what the lambda does. Enclosed in is everything this function does
After you figure that out you only need to know that that construction passes an instance of matching class (look at what's the expected argument type in the schedule()
call) with it's only method doing exactly the same as the lambda expression we've just analyzed.
add a comment |Â
up vote
1
down vote
For lambdas:
Left side is arguments, what you take. Enclosed in ()
are all the arguments this function takes
->
indicates that it's a function that takes what's on the left and passes it on to the right for processing
Right side is the body - what the lambda does. Enclosed in is everything this function does
After you figure that out you only need to know that that construction passes an instance of matching class (look at what's the expected argument type in the schedule()
call) with it's only method doing exactly the same as the lambda expression we've just analyzed.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
For lambdas:
Left side is arguments, what you take. Enclosed in ()
are all the arguments this function takes
->
indicates that it's a function that takes what's on the left and passes it on to the right for processing
Right side is the body - what the lambda does. Enclosed in is everything this function does
After you figure that out you only need to know that that construction passes an instance of matching class (look at what's the expected argument type in the schedule()
call) with it's only method doing exactly the same as the lambda expression we've just analyzed.
For lambdas:
Left side is arguments, what you take. Enclosed in ()
are all the arguments this function takes
->
indicates that it's a function that takes what's on the left and passes it on to the right for processing
Right side is the body - what the lambda does. Enclosed in is everything this function does
After you figure that out you only need to know that that construction passes an instance of matching class (look at what's the expected argument type in the schedule()
call) with it's only method doing exactly the same as the lambda expression we've just analyzed.
answered yesterday
Deltharis
1,64911125
1,64911125
add a comment |Â
add a comment |Â
up vote
-1
down vote
Lambda expressions basically express instances of functional interfaces.
In a way Lambda expression will be: (lambda operator params) -> body
() -> System.out.println("This means Lambda expression is not taking any parameters");
(p) -> System.out.println("Lambda expression with one parameter: " + p);
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
add a comment |Â
up vote
-1
down vote
Lambda expressions basically express instances of functional interfaces.
In a way Lambda expression will be: (lambda operator params) -> body
() -> System.out.println("This means Lambda expression is not taking any parameters");
(p) -> System.out.println("Lambda expression with one parameter: " + p);
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
Lambda expressions basically express instances of functional interfaces.
In a way Lambda expression will be: (lambda operator params) -> body
() -> System.out.println("This means Lambda expression is not taking any parameters");
(p) -> System.out.println("Lambda expression with one parameter: " + p);
Lambda expressions basically express instances of functional interfaces.
In a way Lambda expression will be: (lambda operator params) -> body
() -> System.out.println("This means Lambda expression is not taking any parameters");
(p) -> System.out.println("Lambda expression with one parameter: " + p);
answered yesterday
Archit Sud
725
725
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
add a comment |Â
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
This doesn't answer the question - why the empty lambda. This is just a general explainer of what lambdas are.
– Andrejs
18 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
@Andrejs, why you have down, voted my answer. Did you see what user has asked here? Let me repeat it for you. Here is the last line of the question "I would like to know what the lambda () -> means in that code. I need to write it without using lambdas." He as asked for the meaning of () ->
– Archit Sud
6 hours ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52292953%2fmeaning-of-lambda-in-java%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
25
It's a
Runnable
that does nothing.– ernest_k
yesterday
first argument is runnable, so you are passing anonymous class of instance Runnable in which run method does nothing i.e. is empty.
– SMA
yesterday
3
without lambda, you would need to pass an anonymous Runnable with empty body, like
new Runnable() @Override public void run()
– Alex Salauyou
yesterday