title: What is the better way to use Optional in conditions?
body: <p>I have already written the code, but the thing is I feel there could be better way to write the below code,</p>
  
  <p>This must be possible only from Java 8</p>
  
  <pre><code>private User getUser(String userId) {
      Optional&lt;User&gt; optionalUser = userDAO.getUserById(userId);
      if(optionalUser.isPresent())
          return optionalUser.get();
      throw new UserDefinedException("User not present");
  }
  </code></pre>
  
  <p>I expect to write the above in one line</p>