Statement lambda can be replaced with expression lambda
I do user and invitation validation using the Optional facility
@DeleteMapping("/friends/username")
public
HttpEntity<Boolean> removeFriend(
@ApiParam(value = "The user's name", required = true) @PathVariable String username
) {
Long fromId = authorizationService.getUserId();
return userService.findByUsername(username)
.map(user ->
return friendshipService.findFriendship(fromId, user.getId())
.map(friendship ->
friendshipService.removeFriendship(friendship);
friendship.setToId(friendship.getFromId());
friendship.setFromId(friendship.getToId());
friendshipService.removeFriendship(friendship);
return ResponseEntity.ok(true);
).orElseGet(() -> ResponseEntity.notFound().build());
).orElseThrow(() -> new ResourceNotFoundException("User not found"));
However, IntelliJ is colouring my grey return
https://zapodaj.net/2f48b1a26c392.png.html
But when I remove the return, it highlights to me that there is no return https://zapodaj.net/37605f08165c9.png.html
Could someone explain how it works and what is it all about?
java spring spring-mvc lambda optional
add a comment |
I do user and invitation validation using the Optional facility
@DeleteMapping("/friends/username")
public
HttpEntity<Boolean> removeFriend(
@ApiParam(value = "The user's name", required = true) @PathVariable String username
) {
Long fromId = authorizationService.getUserId();
return userService.findByUsername(username)
.map(user ->
return friendshipService.findFriendship(fromId, user.getId())
.map(friendship ->
friendshipService.removeFriendship(friendship);
friendship.setToId(friendship.getFromId());
friendship.setFromId(friendship.getToId());
friendshipService.removeFriendship(friendship);
return ResponseEntity.ok(true);
).orElseGet(() -> ResponseEntity.notFound().build());
).orElseThrow(() -> new ResourceNotFoundException("User not found"));
However, IntelliJ is colouring my grey return
https://zapodaj.net/2f48b1a26c392.png.html
But when I remove the return, it highlights to me that there is no return https://zapodaj.net/37605f08165c9.png.html
Could someone explain how it works and what is it all about?
java spring spring-mvc lambda optional
add a comment |
I do user and invitation validation using the Optional facility
@DeleteMapping("/friends/username")
public
HttpEntity<Boolean> removeFriend(
@ApiParam(value = "The user's name", required = true) @PathVariable String username
) {
Long fromId = authorizationService.getUserId();
return userService.findByUsername(username)
.map(user ->
return friendshipService.findFriendship(fromId, user.getId())
.map(friendship ->
friendshipService.removeFriendship(friendship);
friendship.setToId(friendship.getFromId());
friendship.setFromId(friendship.getToId());
friendshipService.removeFriendship(friendship);
return ResponseEntity.ok(true);
).orElseGet(() -> ResponseEntity.notFound().build());
).orElseThrow(() -> new ResourceNotFoundException("User not found"));
However, IntelliJ is colouring my grey return
https://zapodaj.net/2f48b1a26c392.png.html
But when I remove the return, it highlights to me that there is no return https://zapodaj.net/37605f08165c9.png.html
Could someone explain how it works and what is it all about?
java spring spring-mvc lambda optional
I do user and invitation validation using the Optional facility
@DeleteMapping("/friends/username")
public
HttpEntity<Boolean> removeFriend(
@ApiParam(value = "The user's name", required = true) @PathVariable String username
) {
Long fromId = authorizationService.getUserId();
return userService.findByUsername(username)
.map(user ->
return friendshipService.findFriendship(fromId, user.getId())
.map(friendship ->
friendshipService.removeFriendship(friendship);
friendship.setToId(friendship.getFromId());
friendship.setFromId(friendship.getToId());
friendshipService.removeFriendship(friendship);
return ResponseEntity.ok(true);
).orElseGet(() -> ResponseEntity.notFound().build());
).orElseThrow(() -> new ResourceNotFoundException("User not found"));
However, IntelliJ is colouring my grey return
https://zapodaj.net/2f48b1a26c392.png.html
But when I remove the return, it highlights to me that there is no return https://zapodaj.net/37605f08165c9.png.html
Could someone explain how it works and what is it all about?
java spring spring-mvc lambda optional
java spring spring-mvc lambda optional
asked Sep 15 '17 at 11:39
sdfsdsdfsd
1821210
1821210
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Your statement lambda
param -> return expression;
can be changed to an expression lambda:
param -> expression
Simple, isn't it? Note, that the curly brackets and the semicolon need to be removed.
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
add a comment |
Sometimes I found useful to leave the
braces where they are if the block of code is long enough (I think it improves readability)
In Android Studio you can locally disable the warning using //noinspection CodeBlock2Expr
at the start of the method like in the example below
//noinspection CodeBlock2Expr
button.setOnClickListener((View v) ->
//a long single method call...
);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46238702%2fstatement-lambda-can-be-replaced-with-expression-lambda%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your statement lambda
param -> return expression;
can be changed to an expression lambda:
param -> expression
Simple, isn't it? Note, that the curly brackets and the semicolon need to be removed.
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
add a comment |
Your statement lambda
param -> return expression;
can be changed to an expression lambda:
param -> expression
Simple, isn't it? Note, that the curly brackets and the semicolon need to be removed.
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
add a comment |
Your statement lambda
param -> return expression;
can be changed to an expression lambda:
param -> expression
Simple, isn't it? Note, that the curly brackets and the semicolon need to be removed.
Your statement lambda
param -> return expression;
can be changed to an expression lambda:
param -> expression
Simple, isn't it? Note, that the curly brackets and the semicolon need to be removed.
edited Dec 28 '18 at 11:46
answered Sep 15 '17 at 11:46
SeelenvirtuoseSeelenvirtuose
16.5k42647
16.5k42647
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
add a comment |
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
Works. Thanks. Which in your opinion is a better way to lambda this pastebin.com/imEtjwHp or this pastebin.com/gcaUMYQ4?
– sdfsd
Sep 15 '17 at 11:52
1
1
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
There is no better in this context. Do it as you like. But for me, both code snippets are not readable. This should always be the first criterion for coding.
– Seelenvirtuose
Sep 15 '17 at 11:58
add a comment |
Sometimes I found useful to leave the
braces where they are if the block of code is long enough (I think it improves readability)
In Android Studio you can locally disable the warning using //noinspection CodeBlock2Expr
at the start of the method like in the example below
//noinspection CodeBlock2Expr
button.setOnClickListener((View v) ->
//a long single method call...
);
add a comment |
Sometimes I found useful to leave the
braces where they are if the block of code is long enough (I think it improves readability)
In Android Studio you can locally disable the warning using //noinspection CodeBlock2Expr
at the start of the method like in the example below
//noinspection CodeBlock2Expr
button.setOnClickListener((View v) ->
//a long single method call...
);
add a comment |
Sometimes I found useful to leave the
braces where they are if the block of code is long enough (I think it improves readability)
In Android Studio you can locally disable the warning using //noinspection CodeBlock2Expr
at the start of the method like in the example below
//noinspection CodeBlock2Expr
button.setOnClickListener((View v) ->
//a long single method call...
);
Sometimes I found useful to leave the
braces where they are if the block of code is long enough (I think it improves readability)
In Android Studio you can locally disable the warning using //noinspection CodeBlock2Expr
at the start of the method like in the example below
//noinspection CodeBlock2Expr
button.setOnClickListener((View v) ->
//a long single method call...
);
edited Nov 21 '18 at 22:20
answered Nov 13 '18 at 8:31
MatPagMatPag
12.6k73651
12.6k73651
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46238702%2fstatement-lambda-can-be-replaced-with-expression-lambda%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown