Lambda Expression

Guys I had a question regarding lambda expressions in Java, when the abstract method from the functional interface requires a parameter, is the parameter not mandatory to be inputted in the code block you pass into the abstract method?
5 Replies
JavaBot
JavaBotβ€’2w ago
βŒ› This post has been reserved for your question.
Hey @valer! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
0x150
0x150β€’2w ago
i cant quite figure out what the second part of the question is. do you mean that the parameter is optional in the lambda? no, it's mandatory if you do
interface FuncItf {
void doSomething(String arg);
}
interface FuncItf {
void doSomething(String arg);
}
the lambda needs to be
FuncItf impl = (arg) -> /* something */;
FuncItf impl = (arg) -> /* something */;
optionally you can also do (String arg) -> /* something */;
Bombe
Bombeβ€’2w ago
You can also name that parameter β€œ_” since a couple of Java versions. In case you don’t plan on using it.
JavaBot
JavaBotβ€’2w ago
πŸ’€ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
JavaBot
JavaBotβ€’7d ago
Post Closed
This post has been closed by <@1265852855458332673>.

Did you find this page helpful?