title: Elegant solution for two Optionals, if one is present the other must not be empty
body: <p>I look for a more elegant solution of this code:</p>
  
  <pre><code>var first = Optional.ofNullable(a);
  var second = Optional.ofNullable(b);
  if ((unit.isPresent() &amp;&amp; value.isEmpty()) || (value.isPresent() &amp;&amp; 
       unit.isEmpty())) {
    throw new ExpWhatever();
  }
  </code></pre>
  
  <p>Conditions are:</p>
  
  <ul>
  <li>if both optionals are null -> ok, no error/excpt.</li>
  <li>if one of the given optionals is present the other must not be empty too (otherwise: excpt.)</li>
  </ul>
  
  <p>Thanks for any ideas or help.</p>