2017-09-15 2 views
6

私は、IntelliJのは、オプションの機能がステートメントラムダを、発現ラムダ

@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")); 

を使用して、ユーザーと招待の検証着色されない私の灰色のリターンと交換することができる https://zapodaj.net/2f48b1a26c392.png.html しかし、私はリターンを削除すると、それは私に浮き彫りに返品がないことを確認してください https://zapodaj.net/37605f08165c9.png.html

誰かがどのように動作するのか、それについては何を説明できますか?そのような単純な

答えて

17

あなたのステートメントラムダ

user -> { return expression; } 

は、発現ラムダに変更することができます:中括弧とセミコロンをする必要があること

user -> expression 

注意、除去された。

+0

作品。ありがとう。あなたの意見では、このhttps://pastebin.com/imEtjwHpまたはこのhttps://pastebin.com/gcaUMYQ4をラムダするより良い方法はありますか? – sdfsd

+0

このコンテキストには_better_はありません。あなたが好きなようにしてください。しかし、私にとっては、両方のコードスニペットを読むことはできません。これは常にコーディングの最初の基準になります。 – Seelenvirtuose