title: contains-method in binary tree always return false java
body: <p>Can someone explain why this method always return false? Even though the statement <code>if(value == node.getValue())</code> is true the method returns false. Something to do with recursion? I solved it by using a booelan-variable instead but I'm still curious why this doesn't work. Thanks.</p>
  
  <pre><code>public boolean contains(Node node, Integer value) {
  
      if(node != null &amp;&amp; node.hasValue()) 
          if(value == node.getValue()) 
              return true;
  
      if(node.hasLeft())
          contains(node.getLeft(), value);
      if(node.hasRight())
          contains(node.getRight(), value);
  
      return false;
  }
  </code></pre>
  
  <p>My solution(bool is an instance-variable):</p>
  
  <pre><code>public boolean contains2(Node node, Integer value) {
  
      if(node != null &amp;&amp; node.hasValue()) 
          if(value == node.getValue()) 
              bool = true;
  
      if(node.hasLeft())
          contains2(node.getLeft(), value);
      if(node.hasRight())
          contains2(node.getRight(), value);
  
      return bool;
  }
  </code></pre>