title: Check if a field is true or false with reflections in java
body: <p>Currently trying to code some menu functionality and wondered if there’s a way to find out if a boolean field is true or false. This is the code I’m currently trying but I get an error</p>
  
  <pre><code>try{
  
       field = a.getClass().getField(b); 
  
       if(toggle==1&amp;&amp;field){
       }else if(toggle==1&amp;&amp;!field){
         field.set(a, true);
       }else if(toggle==0&amp;&amp;!field){
       }else if(toggle==0&amp;&amp;field){
         field.set(a, false);
       }
  }catch (NullPointerException e) {
  }catch (NoSuchFieldException e) {
  }catch (IllegalAccessException e) {
  }
  </code></pre>
  
  <p>The error is</p>
  
  <pre><code>The operator &amp;&amp; is undefined for the argument type(s) boolean, Field
  </code></pre>