title: How to write instanceof with Java 8?
body: <p>I am new in Java 8 Optional. I have to change the following code : </p>
  
  <pre><code>@RequestMapping(value = "/account",
              method = RequestMethod.GET,
              produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;UserDTO&gt; getAccount() {
      return 
          Optional.ofNullable(userService.getUserWithAuthorities())
          .map(user -&gt; 
              new ResponseEntity&lt;&gt;(
                  new UserDTO(
                      user.getLogin(),
                      null,
                      user.getFirstName(),
                      user.getLastName(),
                      user.getEmail(),
                      "",
                      user.getLangKey(),
                      user.getAuthorities()
                          .stream()
                          .map(Authority::getName)
                          .collect(Collectors.toList())
                  ),
                  HttpStatus.OK
              )
          )
          .orElse(new ResponseEntity&lt;&gt;(HttpStatus.INTERNAL_SERVER_ERROR));
  }
  </code></pre>
  
  <p>I want to create a different ResponseEntity according to the instance of <code>user</code>.
  How i can write the equivalent of the following code:</p>
  
  <pre><code>if(user instanceof Admin )
  {
  // my logic
  }
  else if(user instanceof NormalUser)
  {
  // my logic
  }
  </code></pre>
  
  <p>Thanks</p>