title: Java Lambda Expression for if condition - not expected here
body: <p>Consider the case where an if condition needs to evaluate an array or a List. A simple example: check if all elements are true. But I'm looking for <strong>generic</strong> way to do it</p>
  
  <p>Normally I'd do it like that:</p>
  
  <pre><code>boolean allTrue = true;
  for (Boolean bool : bools){
      if (!bool) {
          allTrue = false;
          break;
       }
  }
  if (allTrue){
       // do Something
  }
  </code></pre>
  
  <p>But now I'd like to hide it into my if condition. I tried using Lambda Expressions for this, but it's not working:</p>
  
  <pre><code>if (() -&gt; {
      for (Boolean bool : bools)
          if (!bool)
              return false;
      return true;
  }){
        // do something
  }
  </code></pre>
  
  <p>If this were working I could do something more complicated like</p>
  
  <pre><code>if (() -&gt; {
     int number = 0;
     for (MyObject myobject : myobjects)
         if (myObject.getNumber() != 0)
             numbers++;
     if (numbers &gt; 2) 
         return false;
     return true;
   }{
       //do something
   }
  </code></pre>
  
  <p>Is there a better way to do it is it just a syntax error?</p>
  
  <p><strong>UPDATE</strong>
  I'm not talking about the boolean array, rather looking for a generic way to achieve that.</p>