title: Binary Tree method instance
body: <p>When I was coding a generic "BinaryTree", I needed a method to sum the values of all left subtrees in a tree. This method should return an integer value in a recursive way. However, when I tried to add the root value to the summation, I couldn't cast the "T" value to "int" because the "T" value is incompatible. I created a child class that extends from "BinaryTree" using integer type. In this case, I needed to create the method in my parent class because the recursive call needs to use the method in the parent class and it is a bit annoying me. I think that there is another way to avoid this behavior. Is there a way to avoid creating the method in my parent class?</p>
  
  <p>Binary Tree Class:</p>
  
  <pre><code>public class BinaryTree&lt;T&gt; {
  
  protected T root= null;
  protected BinaryTree&lt;T&gt; left= null, right= null;
  
   //All binary tree here
  
  Integer sumLeft() {
      return 0;
  }
  </code></pre>
  
  <p>Binary Tree Integer</p>
  
  <pre><code>public class BinaryTreeInteger extends BinaryTree&lt;Integer&gt; {
  //All code here
  
  Integer sumLeft() {
      int suma = 0;       
      if (isLeaf()) {            
          return getRaiz();
      }
      if (left != null) {
  
              if (!left.EsHoja()) {
                  suma += left.getRaiz() + left.sumLeft();
              } else {
                  suma += left.sumLeft();
              }              
  
      }
      if (right != null &amp;&amp; !right.isLeaf()) {
  
              suma += right.sumLeft();                
  
      }
      return suma;
  }
  
  }
  
  }
  </code></pre>